afmotion 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/AFMotion.gemspec +19 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/README.md +135 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +6 -0
- data/examples/AppDotNet/.gitignore +13 -0
- data/examples/AppDotNet/Gemfile +4 -0
- data/examples/AppDotNet/Gemfile.lock +48 -0
- data/examples/AppDotNet/Rakefile +10 -0
- data/examples/AppDotNet/app/app_delegate.rb +28 -0
- data/examples/AppDotNet/app/global_timeline_view_controller.rb +84 -0
- data/examples/AppDotNet/app/post.rb +23 -0
- data/examples/AppDotNet/app/post_table_view_cell.rb +44 -0
- data/examples/AppDotNet/app/user.rb +9 -0
- data/examples/AppDotNet/resources/profile-image-placeholder.png +0 -0
- data/examples/AppDotNet/resources/profile-image-placeholder@2x.png +0 -0
- data/examples/AppDotNet/spec/main_spec.rb +9 -0
- data/examples/AppDotNet/vendor/Podfile.lock +11 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +574 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1187 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +341 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +108 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +237 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +136 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +131 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +44 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +145 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +652 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +169 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +180 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/AFNetworking.podspec +28 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/LICENSE +19 -0
- data/examples/AppDotNet/vendor/Pods/AFNetworking/README.md +179 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +574 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +108 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +44 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/examples/AppDotNet/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +574 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +108 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFNetworking.h +44 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/examples/AppDotNet/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.markdown +26 -0
- data/examples/AppDotNet/vendor/Pods/Pods-Acknowledgements.plist +56 -0
- data/examples/AppDotNet/vendor/Pods/Pods-prefix.pch +12 -0
- data/examples/AppDotNet/vendor/Pods/Pods-resources.sh +19 -0
- data/examples/AppDotNet/vendor/Pods/Pods.bridgesupport +617 -0
- data/examples/AppDotNet/vendor/Pods/Pods.xcconfig +7 -0
- data/examples/AppDotNet/vendor/Pods/Pods.xcodeproj/project.pbxproj +998 -0
- data/examples/AppDotNet/vendor/Pods/PodsDummy_Pods.m +4 -0
- data/lib/afmotion/http.rb +55 -0
- data/lib/afmotion/http_client.rb +121 -0
- data/lib/afmotion/http_result.rb +25 -0
- data/lib/afmotion/image.rb +10 -0
- data/lib/afmotion/operation.rb +65 -0
- data/lib/afmotion/patch/NSString_NSUrl.rb +11 -0
- data/lib/afmotion/version.rb +5 -0
- data/lib/afmotion.rb +16 -0
- data/pkg/afmotion-0.0.1.gem +0 -0
- data/spec/http_client_spec.rb +104 -0
- data/spec/http_spec.rb +26 -0
- data/spec/operation_spec.rb +41 -0
- data/vendor/Podfile.lock +11 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +574 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1187 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +341 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +108 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +237 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +136 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +131 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +44 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +145 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +652 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +169 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +180 -0
- data/vendor/Pods/AFNetworking/AFNetworking.podspec +28 -0
- data/vendor/Pods/AFNetworking/LICENSE +19 -0
- data/vendor/Pods/AFNetworking/README.md +179 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +574 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +108 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +44 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +574 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +108 -0
- data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +44 -0
- data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +295 -0
- data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/Pods-Acknowledgements.markdown +26 -0
- data/vendor/Pods/Pods-Acknowledgements.plist +56 -0
- data/vendor/Pods/Pods-prefix.pch +12 -0
- data/vendor/Pods/Pods-resources.sh +19 -0
- data/vendor/Pods/Pods.bridgesupport +617 -0
- data/vendor/Pods/Pods.xcconfig +7 -0
- data/vendor/Pods/PodsDummy_Pods.m +4 -0
- metadata +218 -0
data/.gitignore
ADDED
data/AFMotion.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/afmotion/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "afmotion"
|
6
|
+
s.version = AFMotion::VERSION
|
7
|
+
s.authors = ["Clay Allsopp"]
|
8
|
+
s.email = ["clay.allsopp@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/clayallsopp/AFMotion"
|
10
|
+
s.summary = "A RubyMotion Wrapper for AFNetworking"
|
11
|
+
s.description = "A RubyMotion Wrapper for AFNetworking"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_dependency "motion-cocoapods", ">= 1.2.1"
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
end
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
afmotion (0.0.1)
|
5
|
+
motion-cocoapods (>= 1.2.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (3.2.8)
|
11
|
+
i18n (~> 0.6)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
addressable (2.3.2)
|
14
|
+
cocoapods (0.15.2)
|
15
|
+
activesupport (~> 3.2.6)
|
16
|
+
colored (~> 1.2)
|
17
|
+
escape (~> 0.0.4)
|
18
|
+
faraday (~> 0.8.1)
|
19
|
+
json (~> 1.7.3)
|
20
|
+
octokit (~> 1.7)
|
21
|
+
open4 (~> 1.3.0)
|
22
|
+
rake (~> 0.9.0)
|
23
|
+
xcodeproj (~> 0.3.5)
|
24
|
+
colored (1.2)
|
25
|
+
escape (0.0.4)
|
26
|
+
faraday (0.8.4)
|
27
|
+
multipart-post (~> 1.1)
|
28
|
+
faraday_middleware (0.9.0)
|
29
|
+
faraday (>= 0.7.4, < 0.9)
|
30
|
+
hashie (1.2.0)
|
31
|
+
i18n (0.6.1)
|
32
|
+
json (1.7.5)
|
33
|
+
motion-cocoapods (1.2.1)
|
34
|
+
cocoapods (>= 0.14.0)
|
35
|
+
multi_json (1.3.6)
|
36
|
+
multipart-post (1.1.5)
|
37
|
+
octokit (1.18.0)
|
38
|
+
addressable (~> 2.2)
|
39
|
+
faraday (~> 0.8)
|
40
|
+
faraday_middleware (~> 0.8)
|
41
|
+
hashie (~> 1.2)
|
42
|
+
multi_json (~> 1.3)
|
43
|
+
open4 (1.3.0)
|
44
|
+
rake (0.9.2.2)
|
45
|
+
xcodeproj (0.3.5)
|
46
|
+
activesupport (~> 3.2.6)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
afmotion!
|
53
|
+
rake
|
data/README.md
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# AFMotion
|
2
|
+
|
3
|
+
AFMotion is a thin RubyMotion wrapper for [AFNetworking](https://github.com/AFNetworking/AFNetworking), the absolute best networking library on iOS.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
AFMotion can be used with standalone URL requests:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
AFMotion::HTTP.get("http://google.com") do |result|
|
11
|
+
p result.body
|
12
|
+
end
|
13
|
+
|
14
|
+
AFMotion::JSON.get("http://jsonip.com") do |result|
|
15
|
+
p result.object["ip"]
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
### Web Services
|
20
|
+
|
21
|
+
If you're interacting with a web service, you can use `AFHTTPClient` with this nice wrapper:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# DSL Mapping to properties of AFHTTPClient
|
25
|
+
|
26
|
+
AFMotion::Client.build_shared("https://alpha-api.app.net/") do
|
27
|
+
header "Accept", "application/json"
|
28
|
+
|
29
|
+
operation :json
|
30
|
+
end
|
31
|
+
|
32
|
+
AFMotion::Client.shared.get("stream/0/posts/stream/global") do |result|
|
33
|
+
if result.success?
|
34
|
+
p result.object
|
35
|
+
elsif result.failure?
|
36
|
+
p result.error.localizedDescription
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
### Images
|
42
|
+
|
43
|
+
Loading images from the internet is pretty common. AFNetworking's existing methods aren't bad at all, but just incase you want extra Ruby:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
image_view = UIImageView.alloc.initWithFrame CGRectMake(0, 0, 100, 100)
|
47
|
+
image_view.url = "http://i.imgur.com/r4uwx.jpg"
|
48
|
+
|
49
|
+
# or
|
50
|
+
|
51
|
+
placeholder = UIImage.imageNamed "placeholder-avatar"
|
52
|
+
image_view.url = {url: "http://i.imgur.com/r4uwx.jpg", placeholder: placeholder}
|
53
|
+
```
|
54
|
+
|
55
|
+
## Overview
|
56
|
+
|
57
|
+
### Results
|
58
|
+
|
59
|
+
Each AFMotion wrapper callback yields an `AFMotion::HTTPResult` object. This object has properties like so:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
AFMotion::some_function do |result|
|
63
|
+
# result.operation is the AFURLConnectionOperation instance
|
64
|
+
p result.operation.inspect
|
65
|
+
|
66
|
+
if result.success?
|
67
|
+
# result.object depends on the type of operation.
|
68
|
+
# For JSON and PLIST, this is usually a Hash.
|
69
|
+
# For XML, this is an NSXMLParser
|
70
|
+
# For HTTP, this is an NSURLResponse
|
71
|
+
p result.object
|
72
|
+
|
73
|
+
elsif result.failure?
|
74
|
+
# result.error is an NSError
|
75
|
+
p result.error.localizedDescription
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
### Operations
|
81
|
+
|
82
|
+
There are wrappers for each `AFURLConnectionOperation` subclass, each of the form:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
AFMotion::Operation::[Operation Type].for_request(ns_url_request) do |result|
|
86
|
+
...
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
- `AFMotion::Operation::HTTP.for_request...`
|
91
|
+
- `AFMotion::Operation::JSON.for_request...`
|
92
|
+
- `AFMotion::Operation::XML.for_request...`
|
93
|
+
- `AFMotion::Operation::PLIST.for_request...`
|
94
|
+
|
95
|
+
### One-off Requests
|
96
|
+
|
97
|
+
There are wrappers which automatically run a URL request for a given URL and HTTP method, of the form:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
AFMotion::[Operation Type].[HTTP method](url) do |result|
|
101
|
+
...
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
- `AFMotion::HTTP.get/post/put/patch/delete(url)...`
|
106
|
+
- `AFMotion::JSON.get/post/put/patch/delete(url)...`
|
107
|
+
- `AFMotion::XML.get/post/put/patch/delete(url)...`
|
108
|
+
- `AFMotion::PLIST.get/post/put/patch/delete(url)...`
|
109
|
+
|
110
|
+
### HTTP Client
|
111
|
+
|
112
|
+
If you're constantly accesing a web service, it's a good idea to use an `AFHTTPClient`. Things lets you add a common base URL and request headers to all the requests issued through it, like so:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
client = AFMotion::Client.build("https://alpha-api.app.net/") do
|
116
|
+
header "Accept", "application/json"
|
117
|
+
|
118
|
+
operation :json
|
119
|
+
end
|
120
|
+
|
121
|
+
client.get("stream/0/posts/stream/global") do |result|
|
122
|
+
...
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
If you're constantly used one web service, you can use the `AFMotion::Client.shared` variable have a common reference. It can be set like a normal variable or created with `AFMotion::Client.build_shared`.
|
127
|
+
|
128
|
+
#### Client Building DSL
|
129
|
+
|
130
|
+
The `AFMotion::Client` DSL allows the following properties:
|
131
|
+
|
132
|
+
- `header(header, value)`
|
133
|
+
- `authorization(username: ___, password: ____)` for HTTP Basic auth, or `authorization(token: ____)` for Token based auth.
|
134
|
+
- `operation(operation_type)`. Allows you to set a common operation class for all your client's requests. So if your API is always going to be JSON, you should set `operation(:json)`. Accepts `:json`, `:plist`, `:xml`, or `:http`
|
135
|
+
- `parameter_encoding(encoding)`. Allows you to set a body format for requests parameters. For example, when you send a POST request you might want the parameters to be encoding as a JSON object instead of the traditional `key=val` format. Accepts `:json`, `:plist`, and `:form` (normal encoding).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
require "bundler/setup"
|
6
|
+
Bundler.require :default
|
7
|
+
|
8
|
+
$:.unshift("./lib/")
|
9
|
+
require './lib/afmotion'
|
10
|
+
|
11
|
+
Motion::Project::App.setup do |app|
|
12
|
+
# Use `rake config' to see complete project settings.
|
13
|
+
app.name = 'AFMotion'
|
14
|
+
end
|
data/app/app_delegate.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.8)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
addressable (2.3.2)
|
8
|
+
afmotion (0.0.1)
|
9
|
+
motion-cocoapods (>= 1.2.1)
|
10
|
+
cocoapods (0.15.2)
|
11
|
+
activesupport (~> 3.2.6)
|
12
|
+
colored (~> 1.2)
|
13
|
+
escape (~> 0.0.4)
|
14
|
+
faraday (~> 0.8.1)
|
15
|
+
json (~> 1.7.3)
|
16
|
+
octokit (~> 1.7)
|
17
|
+
open4 (~> 1.3.0)
|
18
|
+
rake (~> 0.9.0)
|
19
|
+
xcodeproj (~> 0.3.5)
|
20
|
+
colored (1.2)
|
21
|
+
escape (0.0.4)
|
22
|
+
faraday (0.8.4)
|
23
|
+
multipart-post (~> 1.1)
|
24
|
+
faraday_middleware (0.9.0)
|
25
|
+
faraday (>= 0.7.4, < 0.9)
|
26
|
+
hashie (1.2.0)
|
27
|
+
i18n (0.6.1)
|
28
|
+
json (1.7.5)
|
29
|
+
motion-cocoapods (1.2.1)
|
30
|
+
cocoapods (>= 0.14.0)
|
31
|
+
multi_json (1.3.6)
|
32
|
+
multipart-post (1.1.5)
|
33
|
+
octokit (1.18.0)
|
34
|
+
addressable (~> 2.2)
|
35
|
+
faraday (~> 0.8)
|
36
|
+
faraday_middleware (~> 0.8)
|
37
|
+
hashie (~> 1.2)
|
38
|
+
multi_json (~> 1.3)
|
39
|
+
open4 (1.3.0)
|
40
|
+
rake (0.9.2.2)
|
41
|
+
xcodeproj (0.3.5)
|
42
|
+
activesupport (~> 3.2.6)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
afmotion
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project'
|
4
|
+
$:.unshift("../../lib")
|
5
|
+
require 'afmotion'
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
# Use `rake config' to see complete project settings.
|
9
|
+
app.name = 'AppDotNet'
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class AppDelegate
|
2
|
+
attr_accessor :navigationController, :window
|
3
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
4
|
+
|
5
|
+
AFMotion::Client.build_shared("https://alpha-api.app.net/") do
|
6
|
+
header "Accept", "application/json"
|
7
|
+
|
8
|
+
operation :json
|
9
|
+
end
|
10
|
+
|
11
|
+
url_cache = NSURLCache.alloc.initWithMemoryCapacity(4 * 1024 * 1024, diskCapacity:20 * 1024 * 1024,diskPath:nil)
|
12
|
+
NSURLCache.setSharedURLCache(url_cache)
|
13
|
+
|
14
|
+
AFNetworkActivityIndicatorManager.sharedManager.enabled = true
|
15
|
+
|
16
|
+
viewController = GlobalTimelineViewController.alloc.initWithStyle(UITableViewStylePlain)
|
17
|
+
|
18
|
+
self.navigationController = UINavigationController.alloc.initWithRootViewController(viewController)
|
19
|
+
self.navigationController.navigationBar.tintColor = UIColor.darkGrayColor
|
20
|
+
|
21
|
+
self.window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
22
|
+
self.window.backgroundColor = UIColor.whiteColor
|
23
|
+
self.window.rootViewController = self.navigationController
|
24
|
+
self.window.makeKeyAndVisible
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
class GlobalTimelineViewController < UITableViewController
|
2
|
+
attr_accessor :posts
|
3
|
+
attr_accessor :activityIndicatorView
|
4
|
+
|
5
|
+
def reload
|
6
|
+
self.activityIndicatorView.startAnimating
|
7
|
+
self.navigationItem.rightBarButtonItem.enabled = true
|
8
|
+
|
9
|
+
Post.fetchGlobalTimelinePosts do |posts, error|
|
10
|
+
if (error)
|
11
|
+
UIAlertView.alloc.initWithTitle("Error",
|
12
|
+
message:error.localizedDescription,
|
13
|
+
delegate:nil,
|
14
|
+
cancelButtonTitle:nil,
|
15
|
+
otherButtonTitles:"OK", nil).show
|
16
|
+
else
|
17
|
+
self.posts = posts
|
18
|
+
end
|
19
|
+
|
20
|
+
self.activityIndicatorView.stopAnimating
|
21
|
+
self.navigationItem.rightBarButtonItem.enabled = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def posts
|
26
|
+
@posts ||= []
|
27
|
+
end
|
28
|
+
|
29
|
+
def posts=(posts)
|
30
|
+
@posts = posts
|
31
|
+
self.tableView.reloadData
|
32
|
+
@posts
|
33
|
+
end
|
34
|
+
|
35
|
+
def loadView
|
36
|
+
super
|
37
|
+
|
38
|
+
self.activityIndicatorView = UIActivityIndicatorView.alloc.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleWhite)
|
39
|
+
self.activityIndicatorView.hidesWhenStopped = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def viewDidLoad
|
43
|
+
super
|
44
|
+
|
45
|
+
self.title = "AFMotion"
|
46
|
+
|
47
|
+
self.navigationItem.leftBarButtonItem = UIBarButtonItem.alloc.initWithCustomView(self.activityIndicatorView)
|
48
|
+
self.navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemRefresh, target:self, action: 'reload')
|
49
|
+
|
50
|
+
self.tableView.rowHeight = 70
|
51
|
+
|
52
|
+
self.reload
|
53
|
+
end
|
54
|
+
|
55
|
+
def viewDidUnload
|
56
|
+
self.activityIndicatorView = nil
|
57
|
+
|
58
|
+
super
|
59
|
+
end
|
60
|
+
|
61
|
+
def tableView(tableView, numberOfRowsInSection:section)
|
62
|
+
self.posts.count
|
63
|
+
end
|
64
|
+
|
65
|
+
def tableView(tableView, cellForRowAtIndexPath:indexPath)
|
66
|
+
@@identifier ||= "Cell"
|
67
|
+
|
68
|
+
cell = tableView.dequeueReusableCellWithIdentifier(@@identifier) || begin
|
69
|
+
PostTableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:@@identifier)
|
70
|
+
end
|
71
|
+
|
72
|
+
cell.post = self.posts[indexPath.row]
|
73
|
+
|
74
|
+
cell
|
75
|
+
end
|
76
|
+
|
77
|
+
def tableView(tableView, heightForRowAtIndexPath:indexPath)
|
78
|
+
PostTableViewCell.heightForCellWithPost(self.posts[indexPath.row])
|
79
|
+
end
|
80
|
+
|
81
|
+
def tableView(tableView, didSelectRowAtIndexPath:indexPath)
|
82
|
+
tableView.deselectRowAtIndexPath(indexPath, animated:true)
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Post
|
2
|
+
attr_accessor :id, :text, :user
|
3
|
+
|
4
|
+
def initialize(attributes = {})
|
5
|
+
self.id = attributes["id"].to_i
|
6
|
+
self.text = attributes["text"].to_s
|
7
|
+
self.user = User.new(attributes["user"])
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.fetchGlobalTimelinePosts(&callback)
|
11
|
+
AFMotion::Client.shared.get("stream/0/posts/stream/global") do |result|
|
12
|
+
if result.success?
|
13
|
+
posts = []
|
14
|
+
result.object["data"].each do |attributes|
|
15
|
+
posts << Post.new(attributes)
|
16
|
+
end
|
17
|
+
callback.call(posts, nil)
|
18
|
+
else
|
19
|
+
callback.call([], result.error)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class PostTableViewCell < UITableViewCell
|
2
|
+
attr_accessor :post
|
3
|
+
|
4
|
+
def initWithStyle(style, reuseIdentifier:reuseIdentifier)
|
5
|
+
super
|
6
|
+
|
7
|
+
self.textLabel.adjustsFontSizeToFitWidth = true
|
8
|
+
self.textLabel.textColor = UIColor.darkGrayColor
|
9
|
+
self.detailTextLabel.font = UIFont.systemFontOfSize 12
|
10
|
+
self.detailTextLabel.numberOfLines = 0
|
11
|
+
self.selectionStyle = UITableViewCellSelectionStyleGray
|
12
|
+
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def post=(post)
|
17
|
+
@post = post
|
18
|
+
|
19
|
+
self.textLabel.text = self.post.user.username
|
20
|
+
self.detailTextLabel.text = self.post.text
|
21
|
+
self.imageView.url = {url: self.post.user.avatar_url.to_url, placeholder: UIImage.imageNamed("profile-image-placeholder")}
|
22
|
+
|
23
|
+
self.setNeedsLayout
|
24
|
+
|
25
|
+
@post
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.heightForCellWithPost(post)
|
29
|
+
sizeToFit = post.text.sizeWithFont(UIFont.systemFontOfSize(12), constrainedToSize: CGSizeMake(220, Float::MAX), lineBreakMode:UILineBreakModeWordWrap)
|
30
|
+
|
31
|
+
return [70, sizeToFit.height + 45].max
|
32
|
+
end
|
33
|
+
|
34
|
+
def layoutSubviews
|
35
|
+
super
|
36
|
+
|
37
|
+
self.imageView.frame = CGRectMake(10, 10, 50, 50);
|
38
|
+
self.textLabel.frame = CGRectMake(70, 10, 240, 20);
|
39
|
+
|
40
|
+
detailTextLabelFrame = CGRectOffset(self.textLabel.frame, 0, 25);
|
41
|
+
detailTextLabelFrame.size.height = self.class.heightForCellWithPost(self.post) - 45
|
42
|
+
self.detailTextLabel.frame = detailTextLabelFrame
|
43
|
+
end
|
44
|
+
end
|
Binary file
|
Binary file
|