waterwheel 4.3.4

waterwheel 4.3.4

测试已测试
语言语言 SwiftSwift
许可证 自定义
发布最新发布2017年10月
SwiftSwift 版本3.0
SPM支持 SPM

Kyle Browning 维护。



 
依赖
Alamofire~> 4.0
ObjectMapper~> 2.0
SwiftyJSON= 3.1.0
SwiftyUserDefaults>= 0
 

  • Kyle Browning

Waterwheel - Drupal SDK

Waterwheel Swift SDK for Drupal

Waterwheel 使得将 Drupal 作为 iOS、macOS、tvOS 或 watchOS 的后端使用变得愉快,通过将 Drupal API 的最常用功能结合在一个 SDK 中。 - 前称为 Drupal iOS SDK。

特性配置使用安装需求


4.x 版特性

  • [x] 会话管理
  • [x] 基本认证
  • [x] Cookie 认证
  • [x] 实体 CRUD
  • [x] 本地缓存
  • [x] LoginViewController
  • [ ] SignupViewController
  • [x] AuthButton
  • [x] 将视图集成到 Table Views

返回顶部

配置

  1. import waterwheel
  2. (可选)如果您不使用 HTTPS,您将不得不启用 NSAppTransportSecurity

使用

下面的代码将为您提供与 Drupal 网站通信的基本特性访问权限。

// Sets the URL to your Drupal site.
waterwheel.setDrupalURL("http://waterwheel-swift.com")

请注意,waterwheel 大量使用 Closures,这允许我们将函数作为返回值传递或在变量中存储。

登录

下面的代码将为每个 API 调用设置基本认证。

// Sets HTTPS Basic Authentication Credentials.
waterwheel.setBasicAuthUsernameAndPassword("test", password: "test2");

如果您不想使用基本认证,而想使用 cookie,waterwheel 提供了执行此操作的身份验证方法。会话由您处理,关闭应用程序并重新打开它时将恢复状态。

waterwheel.login(usernameField.text!, password: passwordField.text!) { (success, response, json, error) in
    if (success) {
        print("logged in")
    } else {
        print("failed to login")
    }
}

Waterwheel 提供了一个 waterwheelAuthButton 来放在您的应用程序中的任何位置。下面的代码是针对 iOS 的,因为它依赖于 UIKit。

let loginButton = waterwheelAuthButton()
// When we press Login, lets show our Login view controller.
loginButton.didPressLogin = {
  waterwheel.login(usernameField.text!, password: passwordField.text!) { (success, response, json, error) in
      if (success) {
          print("successful login")
      } else {
          print("failed to login")
      }
  }
}

loginButton.didPressLogout = { (success, error) in
    print("logged out")
}
self.view.addSubview(loginButton)

将这一步进一步扩展,水车还提供了一个 waterwheelLoginViewController。您可以根据需要对该控制器进行派生并重写。为了我们的目的,我们将使用默认实现。

首先,我们构建自己的 waterwheelLoginViewController 并设置我们的 loginRequestCompletedlogoutRequestCompleted 闭包

// Lets build our default waterwheelLoginViewController.
let vc = waterwheelLoginViewController()

//Lets add our closure that will be run when the request is completed.
vc.loginRequestCompleted = { (success, error) in
    if (success) {
        // Do something related to a successful login
        print("successful login")
        self.dismissViewControllerAnimated(true, completion: nil)
    } else {
        print (error)
    }
}
vc.logoutRequestCompleted = { (success, error) in
    if (success) {
        print("successful logout")
        // Do something related to a successful logout
        self.dismissViewControllerAnimated(true, completion: nil)
    } else {
        print (error)
    }
}

完成这些操作后,我们现在可以向我们的 waterwheelAuthButton 说明当有人点击登录时要执行什么操作。当然,您可以在自己的实现中手动处理所有这些,但出于我们的目的,我们将仅使用水车提供的内容。

在这里,我们实例化一个新的 waterwheelAuthButton 并说明当有人点击登录和注销时我们希望发生什么。

let loginButton = waterwheelAuthButton()
// When we press Login, lets show our Login view controller.
loginButton.didPressLogin = {
    // Lets Present our Login View Controller since this closure is for the loginButton press
    self.presentViewController(vc, animated: true, completion: nil)
}

loginButton.didPressLogout = { (success, error) in
    print("logged out")
}
self.view.addSubview(loginButton)

由于这两个视图知道你是否已登录或注销,因此它们将始终显示正确的按钮状态(登录或注销)并执行相应的操作。UI 由您决定,但默认情况下,您将获得用户名、密码、提交和取消按钮。到此为止,您可以选择忽略这些类并使用水车提供的方法并深入集成到自己的 UI 中。

节点方法

获取

// Get Node 36
waterwheel.nodeGet(nodeId: "36", params: nil, completionHandler: { (success, response, json, error) in
  print(response)
})

创建/发布

//build our node body
let body = [
    "type": [
        [
            "target_id": "article"
        ]
    ],
    "title": [
        [
            "value": "Hello World"
        ]
    ],
    "body": [
        [
            "value": "How are you?"
        ]
    ]
]

// Create a new node.
waterwheel.entityPost(entityType: .Node, params: body) { (success, response, json, error) in
    if (success) {
        print(response)
    } else {
        print(error)
    }
}

更新/PUT/PATCH

// Update an existing node
waterwheel.nodePatch(nodeId: "36", node: body) { (success, response, json, error) in
    print(response);
}

删除

// Delete an existing node
waterwheel.nodeDelete(nodeId: "36", params: nil, completionHandler: { (success, response, json, error) in
    print(response)
})

实体请求

由于节点相当具体,Waterwheel还为所有的实体类型提供了实体方法。

实体获取

waterwheel.entityGet(entityType: .Node, entityId: "36", params: params, completionHandler: completionHandler)

实体发布

waterwheel.sharedInstance.entityPost(entityType: .Node, params: node, completionHandler: completionHandler)

实体patch

waterwheel.entityPatch(entityType: .Node, entityId: "36", params: nodeObject, completionHandler: completionHandler)

实体删除

waterwheel.entityDelete(entityType: .Node, entityId: entityId, params: params, completionHandler: completionHandler)

安装

Waterwheel提供两种安装路径。选择你喜欢的!

安装

通信

  • 如果您 需要帮助,请使用 Stack Overflow。(标记‘waterwheel-swift’)
  • 如果 发现了错误,请打开一个问题。
  • 如果 有功能请求,请打开一个问题。
  • 如果您 想要做出贡献,请提交一个 pull request。

返回顶部

Drupal 兼容性

框架正在跟踪 Drupal 8。随着 8 中的新功能出现,它们将尽快添加。由于 Drupal 7 和 Drupal 8 在 API 方面完全不同,您将需要根据您的 Drupal 版本使用水车的正确版本。

需求

  • iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 7.3+
waterwheel版本 Drupal版本 注意
4.x Drupal 8(Swift)
3.x Drupal 8(Obj-C)
2.x Drupal 6-7(Obj-C) 需要Services模块

返回顶部