elevate 0.3.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elevate (0.3.1)
4
+ elevate (0.3.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -101,10 +101,6 @@ class ArtistsViewController < UITableViewController
101
101
  end
102
102
  ```
103
103
 
104
- Requirements
105
- ------------
106
- * **iOS 6.x and higher** (due to `setDelegateQueue` being [horribly broken](http://openradar.appspot.com/10529053) on iOS 5.x.)
107
-
108
104
  Installation
109
105
  ------------
110
106
  Update your Gemfile:
@@ -0,0 +1,16 @@
1
+ module Elevate
2
+ module HTTP
3
+ class RequestError < RuntimeError
4
+ def initialize(error)
5
+ super(error.localizedDescription)
6
+
7
+ @code = error.code
8
+ end
9
+
10
+ attr_reader :code
11
+ end
12
+
13
+ class OfflineError < RequestError
14
+ end
15
+ end
16
+ end
@@ -43,17 +43,12 @@ module HTTP
43
43
  options[:headers]["Content-Type"] = "application/json"
44
44
  end
45
45
 
46
- request = HTTPRequest.new(method, url, options)
47
-
48
- coordinator = IOCoordinator.for_thread
49
-
50
- coordinator.signal_blocked(request) if coordinator
51
- response = JSONHTTPResponse.new(request.response)
52
- coordinator.signal_unblocked(request) if coordinator
46
+ response = send_request(method, url, options)
47
+ raise_error(response.error) if response.error
53
48
 
49
+ response = JSONHTTPResponse.new(response)
54
50
  if response.error == nil && block_given?
55
51
  result = yield response.body
56
- puts result.inspect
57
52
 
58
53
  result
59
54
  else
@@ -61,6 +56,26 @@ module HTTP
61
56
  end
62
57
  end
63
58
 
59
+ def raise_error(error)
60
+ if error.code == -1009
61
+ raise OfflineError, error
62
+ else
63
+ raise RequestError, response.error
64
+ end
65
+ end
66
+
67
+ def send_request(method, url, options)
68
+ request = HTTPRequest.new(method, url, options)
69
+
70
+ coordinator = IOCoordinator.for_thread
71
+
72
+ coordinator.signal_blocked(request) if coordinator
73
+ response = request.response
74
+ coordinator.signal_unblocked(request) if coordinator
75
+
76
+ response
77
+ end
78
+
64
79
  def url_for(path)
65
80
  path = CFURLCreateStringByAddingPercentEscapes(nil, path.to_s, "[]", ";=&,", KCFStringEncodingUTF8)
66
81
 
@@ -39,7 +39,7 @@ module HTTP
39
39
  return unless started?
40
40
 
41
41
  NetworkThread.cancel(@connection)
42
- @promise.set(nil)
42
+ @promise.fulfill(nil)
43
43
  end
44
44
 
45
45
  def response
@@ -47,7 +47,7 @@ module HTTP
47
47
  start()
48
48
  end
49
49
 
50
- @promise.get()
50
+ @promise.value
51
51
  end
52
52
 
53
53
  def start
@@ -72,18 +72,18 @@ module HTTP
72
72
  end
73
73
 
74
74
  def connection(connection, didFailWithError: error)
75
- puts "ERROR: #{error.localizedDescription}"
75
+ puts "ERROR: #{error.localizedDescription} (code: #{error.code})"
76
76
 
77
77
  @response.error = error
78
78
  @response.freeze
79
79
 
80
- @promise.set(@response)
80
+ @promise.fulfill(@response)
81
81
  end
82
82
 
83
83
  def connectionDidFinishLoading(connection)
84
84
  @response.freeze
85
85
 
86
- @promise.set(@response)
86
+ @promise.fulfill(@response)
87
87
  end
88
88
 
89
89
  def get_authorization_header(credentials)
@@ -51,7 +51,7 @@ module Elevate
51
51
  @result = @target.execute
52
52
  end
53
53
 
54
- rescue => e
54
+ rescue Exception => e
55
55
  @exception = e
56
56
  end
57
57
 
@@ -8,7 +8,14 @@ module Elevate
8
8
  @result = nil
9
9
  end
10
10
 
11
- def get
11
+ def fulfill(result)
12
+ if @lock.tryLockWhenCondition(OUTSTANDING)
13
+ @result = result
14
+ @lock.unlockWithCondition(FULFILLED)
15
+ end
16
+ end
17
+
18
+ def value
12
19
  result = nil
13
20
 
14
21
  @lock.lockWhenCondition(FULFILLED)
@@ -17,11 +24,5 @@ module Elevate
17
24
 
18
25
  result
19
26
  end
20
-
21
- def set(result)
22
- @lock.lockWhenCondition(OUTSTANDING)
23
- @result = result
24
- @lock.unlockWithCondition(FULFILLED)
25
- end
26
27
  end
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module Elevate
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elevate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.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: 2013-02-11 00:00:00.000000000 Z
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -98,6 +98,7 @@ files:
98
98
  - lib/elevate/dispatcher.rb
99
99
  - lib/elevate/dsl.rb
100
100
  - lib/elevate/http/base64.rb
101
+ - lib/elevate/http/errors.rb
101
102
  - lib/elevate/http/http_client.rb
102
103
  - lib/elevate/http/request.rb
103
104
  - lib/elevate/http/response.rb
@@ -130,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  segments:
132
133
  - 0
133
- hash: 421563326578819591
134
+ hash: 3623850089933404602
134
135
  required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  none: false
136
137
  requirements:
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  segments:
141
142
  - 0
142
- hash: 421563326578819591
143
+ hash: 3623850089933404602
143
144
  requirements: []
144
145
  rubyforge_project:
145
146
  rubygems_version: 1.8.24