afmotion 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/README.md +12 -1
- data/lib/afmotion/http.rb +13 -0
- data/lib/afmotion/http_client.rb +0 -1
- data/lib/afmotion/operation.rb +18 -0
- data/lib/afmotion/version.rb +1 -1
- data/spec/http_spec.rb +18 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -52,6 +52,14 @@ Loading images from the internet is pretty common. AFNetworking's existing metho
|
|
52
52
|
image_view.url = {url: "http://i.imgur.com/r4uwx.jpg", placeholder: placeholder}
|
53
53
|
```
|
54
54
|
|
55
|
+
You can also request arbitrary images:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
AFMotion::Image.get("https://www.google.com/images/srpr/logo3w.png") do |result|
|
59
|
+
image_view = UIImageView.alloc.initWithImage(result.object)
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
55
63
|
## Install
|
56
64
|
|
57
65
|
1. `gem install afmotion`
|
@@ -86,6 +94,7 @@ AFMotion::some_function do |result|
|
|
86
94
|
# For JSON and PLIST, this is usually a Hash.
|
87
95
|
# For XML, this is an NSXMLParser
|
88
96
|
# For HTTP, this is an NSURLResponse
|
97
|
+
# For Image, this is a UIImage
|
89
98
|
p result.object
|
90
99
|
|
91
100
|
elsif result.failure?
|
@@ -109,6 +118,7 @@ end
|
|
109
118
|
- `AFMotion::Operation::JSON.for_request...`
|
110
119
|
- `AFMotion::Operation::XML.for_request...`
|
111
120
|
- `AFMotion::Operation::PLIST.for_request...`
|
121
|
+
- `AFMotion::Operation::Image.for_request...`
|
112
122
|
|
113
123
|
### One-off Requests
|
114
124
|
|
@@ -124,7 +134,7 @@ Example:
|
|
124
134
|
|
125
135
|
```ruby
|
126
136
|
AFMotion::HTTP.get("http://google.com", q: "rubymotion") do |result|
|
127
|
-
# sends request to http://google.com?q=
|
137
|
+
# sends request to http://google.com?q=rubymotion
|
128
138
|
end
|
129
139
|
```
|
130
140
|
|
@@ -132,6 +142,7 @@ end
|
|
132
142
|
- `AFMotion::JSON.get/post/put/patch/delete(url)...`
|
133
143
|
- `AFMotion::XML.get/post/put/patch/delete(url)...`
|
134
144
|
- `AFMotion::PLIST.get/post/put/patch/delete(url)...`
|
145
|
+
- `AFMotion::Image.get/post/put/patch/delete(url)...`
|
135
146
|
|
136
147
|
### HTTP Client
|
137
148
|
|
data/lib/afmotion/http.rb
CHANGED
@@ -76,4 +76,17 @@ module AFMotion
|
|
76
76
|
AFPropertyListParameterEncoding
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
module Image
|
81
|
+
include AFMotion::HTTPBuilder
|
82
|
+
|
83
|
+
module_function
|
84
|
+
def request_module
|
85
|
+
AFMotion::Operation::Image
|
86
|
+
end
|
87
|
+
|
88
|
+
def parameter_encoding
|
89
|
+
AFFormURLParameterEncoding
|
90
|
+
end
|
91
|
+
end
|
79
92
|
end
|
data/lib/afmotion/http_client.rb
CHANGED
data/lib/afmotion/operation.rb
CHANGED
@@ -61,5 +61,23 @@ module AFMotion
|
|
61
61
|
)
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
module Image
|
66
|
+
def self.for_request(request, &callback)
|
67
|
+
operation = AFImageRequestOperation.imageRequestOperationWithRequest(request,
|
68
|
+
imageProcessingBlock: lambda {|ui_image|
|
69
|
+
return ui_image
|
70
|
+
},
|
71
|
+
success: lambda { |request, response, ui_image|
|
72
|
+
result = AFMotion::HTTPResult.new(operation, ui_image, nil)
|
73
|
+
callback.call(result)
|
74
|
+
},
|
75
|
+
failure: lambda { |request, response, error|
|
76
|
+
result = AFMotion::HTTPResult.new(operation, nil, error)
|
77
|
+
callback.call(result)
|
78
|
+
}
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
64
82
|
end
|
65
83
|
end
|
data/lib/afmotion/version.rb
CHANGED
data/spec/http_spec.rb
CHANGED
@@ -38,4 +38,22 @@ describe "AFMotion" do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "AFMotion::Image" do
|
43
|
+
before do
|
44
|
+
@result = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should work with an image" do
|
48
|
+
url = "https://www.google.com/images/srpr/logo3w.png"
|
49
|
+
AFMotion::Image.get(url) do |result|
|
50
|
+
@result = result
|
51
|
+
resume
|
52
|
+
end
|
53
|
+
wait_max(10) do
|
54
|
+
@result.nil?.should == false
|
55
|
+
@result.object.is_a?(UIImage).should == true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
41
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: afmotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: motion-cocoapods
|
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash:
|
139
|
+
hash: 77784384284444777
|
140
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
141
|
none: false
|
142
142
|
requirements:
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
segments:
|
147
147
|
- 0
|
148
|
-
hash:
|
148
|
+
hash: 77784384284444777
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
151
|
rubygems_version: 1.8.23
|