spark_api 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -139
- data/VERSION +1 -1
- data/lib/spark_api.rb +2 -2
- data/lib/spark_api/authentication.rb +0 -1
- data/lib/spark_api/authentication/oauth2.rb +1 -1
- data/lib/spark_api/authentication/oauth2_impl/{middleware.rb → faraday_middleware.rb} +18 -15
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +4 -3
- data/lib/spark_api/configuration.rb +2 -0
- data/lib/spark_api/connection.rb +4 -5
- data/lib/spark_api/faraday_middleware.rb +69 -0
- data/lib/spark_api/models/photo.rb +2 -0
- data/spec/mock_helper.rb +3 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/spark_api/{faraday_spec.rb → faraday_middleware_spec.rb} +0 -0
- data/spec/unit/spark_api/paginate_spec.rb +3 -3
- data/spec/unit/spark_api_spec.rb +4 -0
- metadata +42 -72
- data/lib/spark_api/faraday.rb +0 -64
data/History.txt
CHANGED
@@ -1,139 +1,13 @@
|
|
1
|
-
==
|
2
|
-
*
|
3
|
-
|
4
|
-
*
|
5
|
-
==
|
6
|
-
*
|
7
|
-
|
8
|
-
*
|
9
|
-
*
|
10
|
-
==
|
11
|
-
*
|
12
|
-
==
|
13
|
-
*
|
14
|
-
== v0.6.5 2011-08-02
|
15
|
-
* Fixed some recursive gemspec issues from jewler by removing jeweler and going with some of our own custom rake tasks.
|
16
|
-
== v0.6.4 2011-08-02
|
17
|
-
* added public method for the listing carts service specified
|
18
|
-
* added spec for portal listing cart method
|
19
|
-
== v0.6.3 2011-08-02
|
20
|
-
* Fix gemspec error on CLI launch (bundler)
|
21
|
-
== v0.6.2 2011-07-29
|
22
|
-
* Added command to make irb sessions rocktastic
|
23
|
-
== v0.6.1 2011-07-14
|
24
|
-
* Fixed request headers to match api expectations
|
25
|
-
* OAuth2 grant types redesign
|
26
|
-
* "provided" saved searches
|
27
|
-
* Portal account saving
|
28
|
-
== v0.5.9 2011-07-12
|
29
|
-
* Modify Collect to handle FixNums in the case of pagination=count to my/office listings
|
30
|
-
== v0.5.8 2011-07-08
|
31
|
-
* Add finders to SharedListing model
|
32
|
-
* fixed log message
|
33
|
-
== v0.5.7 2011-07-07
|
34
|
-
* Add /my/contact support
|
35
|
-
== v0.5.6 2011-07-07
|
36
|
-
* More build woes.
|
37
|
-
== v0.5.5 2011-07-07
|
38
|
-
== v0.5.4 2011-07-01
|
39
|
-
* Added the add listing methods to the cart instance.
|
40
|
-
* Added the remove listing methods to the cart instance.
|
41
|
-
* Accounts service by office changes
|
42
|
-
== v0.5.3 2011-06-28
|
43
|
-
* API error handling bugfix to log decent messages
|
44
|
-
* Fixed the OAuth flow.
|
45
|
-
* Provide primary image types
|
46
|
-
== v0.5.2 2011-06-23
|
47
|
-
== v0.5.1 2011-06-03
|
48
|
-
* Upgraded dependencies to latest releases.
|
49
|
-
* Added put / delete functionality.
|
50
|
-
* Make method_missing and respond_to? methods match the expected behavior and add specs to define those behaviors.
|
51
|
-
* Properly escape uri paths when making requests.
|
52
|
-
* SavedSearch resource.
|
53
|
-
== v0.4.6 2011-05-13
|
54
|
-
* Added notify option to contacts
|
55
|
-
* Implementation of listing cart resource.
|
56
|
-
* Pass JSON instead of a querystring for the OAuth POST body
|
57
|
-
* API-101 client implementation for sharedlistings service.
|
58
|
-
* Added multiclient support
|
59
|
-
* Change client from sending credentials as request parameters to post data
|
60
|
-
== v0.4.5 2011-05-06
|
61
|
-
* Restrict lists larger than 1,000 scroll items
|
62
|
-
* Fixed logging of oauth2 errors, removed redundant access_token from parameters.
|
63
|
-
== v0.4.4 2011-05-06
|
64
|
-
* Need to skip spec/reports for CI builds (oops).
|
65
|
-
== v0.4.3 2011-05-05
|
66
|
-
* Fixed semi important issue with timeout settings.
|
67
|
-
== v0.4.2 2011-05-03
|
68
|
-
* Fixed some nasty session timeout issues that were reported.
|
69
|
-
* Raise proper exceptions for oauth grant errors.
|
70
|
-
== v0.4.1 2011-04-11
|
71
|
-
* Removed unnecessary finders from property type model
|
72
|
-
* OAuth2 implementation and general auth redesign
|
73
|
-
* Upgraded ruby version supported.
|
74
|
-
* Add finders to Contact model
|
75
|
-
* Adds an inspect to make debug info easier to read
|
76
|
-
* Standard field support for _expanding and nearby
|
77
|
-
== v0.3.9 2011-04-01
|
78
|
-
* Added notes model and specs
|
79
|
-
* Added a primary_logo method to the system info class
|
80
|
-
* Change owner param to arguments hash
|
81
|
-
* Add finders
|
82
|
-
== v0.3.8 2011-03-24
|
83
|
-
* Interface change! Remove api user calls that are all over the place.
|
84
|
-
* Fix for empty count response.
|
85
|
-
* Parse date and times for tour
|
86
|
-
== v0.3.7 2011-03-11
|
87
|
-
* Fix catch miss.
|
88
|
-
* Added tour of homes model.
|
89
|
-
== v0.3.6 2011-03-08
|
90
|
-
* Added account model Also moved finders to a module.
|
91
|
-
== v0.3.5 2011-03-08
|
92
|
-
* changing units on API request logging
|
93
|
-
== v0.3.4 2011-02-08
|
94
|
-
* Fixed escaping special characters in the client. This needs to happen after signing.
|
95
|
-
== v0.3.3 2011-01-28
|
96
|
-
* Add session features to the api client.
|
97
|
-
* Remove redundant debug log call
|
98
|
-
== v0.3.2 2011-01-28
|
99
|
-
* CustomFields class added
|
100
|
-
== v0.3.1 2011-01-27
|
101
|
-
* Prep work for rubygems
|
102
|
-
* doc corrections
|
103
|
-
== v0.3.0 2011-01-17
|
104
|
-
* Added license for release.
|
105
|
-
== v0.2.9 2011-01-12
|
106
|
-
* misc project cleanup
|
107
|
-
== v0.2.8 2011-01-10
|
108
|
-
* Fixed client to use http for all requests (except for session auth) by default. Added :ssl option to enable https for all traffic.
|
109
|
-
* Fixed client connection and resets.
|
110
|
-
== v0.2.7 2011-01-10
|
111
|
-
* Build troubles
|
112
|
-
== v0.2.6 2011-01-10
|
113
|
-
== v0.2.5 2011-01-10
|
114
|
-
== v0.2.4 2011-01-10
|
115
|
-
== v0.2.3 2011-01-10
|
116
|
-
* Handy startup script picking keys from the environment.
|
117
|
-
== v0.2.2 2010-12-29
|
118
|
-
* per_page setting for the client models.
|
119
|
-
* Pagination support for the Spark api client
|
120
|
-
* Added branded? and unbranded? instance methods to Video
|
121
|
-
* Added document model
|
122
|
-
* Added virtual tours model
|
123
|
-
* Added videos model
|
124
|
-
* Contact model and saving
|
125
|
-
* Added `find_by_cart_id' method to Listing model
|
126
|
-
* allow finder to pass thru options
|
127
|
-
* Implemented Listing.find(:all, ...)
|
128
|
-
== v0.2.1 2010-12-29
|
129
|
-
* fixed some error code issues.
|
130
|
-
* corrected default endpoint to include the URL scheme
|
131
|
-
== v0.2.0 2010-12-27
|
132
|
-
* new gemspec
|
133
|
-
* Session caching
|
134
|
-
* Major overhaul on the models for code reuse
|
135
|
-
* added Photo.find_by_listing_key
|
136
|
-
== v0.1.1 2010-12-23
|
137
|
-
* IDX link and market stat models.
|
138
|
-
== v0.1.0 2010-12-13
|
139
|
-
* Initial usable release with request interface and models
|
1
|
+
== v1.1.0 2012-08-07
|
2
|
+
* Upgraded faraday and other gems, cleand up the middleware
|
3
|
+
== v1.0.4 2012-07-26
|
4
|
+
* Moved to github for all development
|
5
|
+
== v1.0.3 2012-07-09
|
6
|
+
* Rental calendar
|
7
|
+
== v1.0.2 2012-05-30
|
8
|
+
* OpenId/Hybrid flow support
|
9
|
+
* OAuthSession does not support symbols as init
|
10
|
+
== v1.0.1 2012-04-30
|
11
|
+
* Fixed yaml config files
|
12
|
+
== v1.0.0 2012-04-20
|
13
|
+
* Switch to spark api branding from flexmls_api
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/spark_api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'json'
|
3
2
|
require 'logger'
|
3
|
+
require 'multi_json'
|
4
4
|
|
5
5
|
require 'spark_api/version'
|
6
6
|
require 'spark_api/configuration'
|
@@ -11,7 +11,7 @@ require 'spark_api/paginate'
|
|
11
11
|
require 'spark_api/request'
|
12
12
|
require 'spark_api/connection'
|
13
13
|
require 'spark_api/client'
|
14
|
-
require 'spark_api/
|
14
|
+
require 'spark_api/faraday_middleware'
|
15
15
|
require 'spark_api/primary_array'
|
16
16
|
require 'spark_api/options_hash'
|
17
17
|
require 'spark_api/models'
|
@@ -217,7 +217,7 @@ module SparkApi
|
|
217
217
|
end
|
218
218
|
|
219
219
|
module OAuth2Impl
|
220
|
-
require 'spark_api/authentication/oauth2_impl/
|
220
|
+
require 'spark_api/authentication/oauth2_impl/faraday_middleware'
|
221
221
|
require 'spark_api/authentication/oauth2_impl/grant_type_base'
|
222
222
|
require 'spark_api/authentication/oauth2_impl/grant_type_refresh'
|
223
223
|
require 'spark_api/authentication/oauth2_impl/grant_type_code'
|
@@ -1,38 +1,41 @@
|
|
1
|
-
|
1
|
+
require 'faraday'
|
2
2
|
|
3
|
+
module SparkApi
|
3
4
|
module Authentication
|
4
|
-
|
5
5
|
module OAuth2Impl
|
6
|
-
|
6
|
+
|
7
7
|
#==OAuth2 Faraday response middleware
|
8
8
|
# HTTP Response after filter to package oauth2 responses and bubble up basic api errors.
|
9
|
-
class
|
10
|
-
|
11
|
-
|
9
|
+
class FaradayMiddleware < Faraday::Response::Middleware
|
10
|
+
|
11
|
+
def initialize(app)
|
12
|
+
super(app)
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_complete(env)
|
16
|
+
body = MultiJson.decode(env[:body])
|
12
17
|
SparkApi.logger.debug("[oauth2] Response Body: #{body.inspect}")
|
13
18
|
unless body.is_a?(Hash)
|
14
19
|
raise InvalidResponse, "The server response could not be understood"
|
15
20
|
end
|
16
|
-
case
|
21
|
+
case env[:status]
|
17
22
|
when 200..299
|
18
23
|
SparkApi.logger.debug("[oauth2] Success!")
|
19
24
|
session = OAuthSession.new(body)
|
20
25
|
else
|
21
26
|
# Handle the WWW-Authenticate Response Header Field if present. This can be returned by
|
22
27
|
# OAuth2 implementations and wouldn't hurt to log.
|
23
|
-
auth_header_error =
|
28
|
+
auth_header_error = env[:request_headers]["WWW-Authenticate"]
|
24
29
|
SparkApi.logger.warn("Authentication error #{auth_header_error}") unless auth_header_error.nil?
|
25
|
-
raise ClientError, {:message => body["error"], :code =>0, :status =>
|
30
|
+
raise ClientError, {:message => body["error"], :code =>0, :status => env[:status]}
|
26
31
|
end
|
27
32
|
SparkApi.logger.debug("[oauth2] Session=#{session.inspect}")
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize(app)
|
32
|
-
super(app)
|
33
|
+
env[:body] = session
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
end
|
37
|
+
Faraday.register_middleware :response, :oauth2_impl => FaradayMiddleware
|
38
|
+
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
@@ -68,9 +68,10 @@ module SparkApi
|
|
68
68
|
}
|
69
69
|
opts[:ssl] = {:verify => false }
|
70
70
|
opts[:url] = endpoint
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
Faraday.register_middleware :response, :faraday_middleware => FaradayMiddleware
|
72
|
+
conn = Faraday::Connection.new(opts) do |conn|
|
73
|
+
conn.response :oauth2_impl
|
74
|
+
conn.adapter Faraday.default_adapter
|
74
75
|
end
|
75
76
|
end
|
76
77
|
def build_url_parameters(parameters={})
|
data/lib/spark_api/connection.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'faraday'
|
3
|
-
require 'faraday_middleware'
|
4
|
-
require 'yajl'
|
5
3
|
|
6
4
|
module SparkApi
|
7
5
|
# =Connection
|
@@ -20,9 +18,10 @@ module SparkApi
|
|
20
18
|
else
|
21
19
|
opts[:url] = @endpoint.sub /^https:/, "http:"
|
22
20
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
|
22
|
+
conn = Faraday.new(opts) do |conn|
|
23
|
+
conn.response :spark_api
|
24
|
+
conn.adapter Faraday.default_adapter
|
26
25
|
end
|
27
26
|
SparkApi.logger.debug("Connection: #{conn.inspect}")
|
28
27
|
conn
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module SparkApi
|
5
|
+
#=Spark API Faraday middleware
|
6
|
+
# HTTP Response after filter to package api responses and bubble up basic api errors.
|
7
|
+
class FaradayMiddleware < Faraday::Response::Middleware
|
8
|
+
include SparkApi::PaginateHelper
|
9
|
+
|
10
|
+
def initialize(app)
|
11
|
+
super(app)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Handles pretty much all the api response parsing and error handling. All responses that
|
15
|
+
# indicate a failure will raise a SparkApi::ClientError exception
|
16
|
+
def on_complete(env)
|
17
|
+
body = MultiJson.decode(env[:body])
|
18
|
+
SparkApi.logger.debug("Response Body: #{body.inspect}")
|
19
|
+
unless body.is_a?(Hash) && body.key?("D")
|
20
|
+
raise InvalidResponse, "The server response could not be understood"
|
21
|
+
end
|
22
|
+
response = ApiResponse.new body
|
23
|
+
paging = response.pagination
|
24
|
+
if paging.nil?
|
25
|
+
results = response
|
26
|
+
else
|
27
|
+
q = CGI.parse(env[:url].query)
|
28
|
+
if q.key?("_pagination") && q["_pagination"].first == "count"
|
29
|
+
results = paging['TotalRows']
|
30
|
+
else
|
31
|
+
results = paginate_response(response, paging)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
case env[:status]
|
35
|
+
when 400
|
36
|
+
hash = {:message => response.message, :code => response.code, :status => env[:status]}
|
37
|
+
|
38
|
+
# constraint violation
|
39
|
+
if response.code == 1053
|
40
|
+
details = body['D']['Details']
|
41
|
+
hash[:details] = details
|
42
|
+
end
|
43
|
+
raise BadResourceRequest,hash
|
44
|
+
when 401
|
45
|
+
# Handle the WWW-Authenticate Response Header Field if present. This can be returned by
|
46
|
+
# OAuth2 implementations and wouldn't hurt to log.
|
47
|
+
auth_header_error = env[:request_headers]["WWW-Authenticate"]
|
48
|
+
SparkApi.logger.warn("Authentication error #{auth_header_error}") unless auth_header_error.nil?
|
49
|
+
raise PermissionDenied, {:message => response.message, :code => response.code, :status => env[:status]}
|
50
|
+
when 404
|
51
|
+
raise NotFound, {:message => response.message, :code => response.code, :status => env[:status]}
|
52
|
+
when 405
|
53
|
+
raise NotAllowed, {:message => response.message, :code => response.code, :status => env[:status]}
|
54
|
+
when 409
|
55
|
+
raise BadResourceRequest, {:message => response.message, :code => response.code, :status => env[:status]}
|
56
|
+
when 500
|
57
|
+
raise ClientError, {:message => response.message, :code => response.code, :status => env[:status]}
|
58
|
+
when 200..299
|
59
|
+
SparkApi.logger.debug("Success!")
|
60
|
+
else
|
61
|
+
raise ClientError, {:message => response.message, :code => response.code, :status => env[:status]}
|
62
|
+
end
|
63
|
+
env[:body] = results
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
Faraday.register_middleware :response, :spark_api => FaradayMiddleware
|
68
|
+
|
69
|
+
end
|
data/spec/mock_helper.rb
CHANGED
@@ -106,9 +106,9 @@ def mock_expired_session()
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def test_connection(stubs)
|
109
|
-
Faraday
|
110
|
-
|
111
|
-
|
109
|
+
Faraday.new(nil, {:headers => SparkApi::Client.new.headers}) do |conn|
|
110
|
+
conn.response :spark_api
|
111
|
+
conn.adapter :test, stubs
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
@@ -139,7 +139,7 @@ describe SparkApi::Paginate do
|
|
139
139
|
"Success": true,
|
140
140
|
"Results": [#{ListingJson.create_all(10)}],
|
141
141
|
#{paginate_json}
|
142
|
-
}
|
142
|
+
}}
|
143
143
|
JSON
|
144
144
|
stub_request(:get, "#{SparkApi.endpoint}/#{SparkApi.version}/listings").
|
145
145
|
with(:query => {
|
@@ -172,7 +172,7 @@ describe SparkApi::Paginate do
|
|
172
172
|
"Success": true,
|
173
173
|
"Results": [#{ListingJson.create_all(10)}],
|
174
174
|
#{paginate_json(2)}
|
175
|
-
}
|
175
|
+
}}
|
176
176
|
JSON
|
177
177
|
stub_request(:get, "#{SparkApi.endpoint}/#{SparkApi.version}/listings").
|
178
178
|
with(:query => {
|
@@ -195,7 +195,7 @@ describe SparkApi::Paginate do
|
|
195
195
|
"Success": true,
|
196
196
|
"Results": [#{ListingJson.create_all(8)}],
|
197
197
|
#{paginate_json(4)}
|
198
|
-
}
|
198
|
+
}}
|
199
199
|
JSON
|
200
200
|
stub_request(:get, "#{SparkApi.endpoint}/#{SparkApi.version}/listings").
|
201
201
|
with(:query => {
|
data/spec/unit/spark_api_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spark_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.4
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Hornseth
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-07
|
19
|
+
date: 2012-08-07 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -24,34 +24,18 @@ dependencies:
|
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
27
|
+
hash: 61
|
28
28
|
segments:
|
29
29
|
- 0
|
30
|
-
-
|
31
|
-
-
|
32
|
-
version: 0.
|
30
|
+
- 8
|
31
|
+
- 1
|
32
|
+
version: 0.8.1
|
33
33
|
requirement: *id001
|
34
34
|
prerelease: false
|
35
35
|
name: faraday
|
36
36
|
type: :runtime
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
- 7
|
47
|
-
- 0
|
48
|
-
version: 0.7.0
|
49
|
-
requirement: *id002
|
50
|
-
prerelease: false
|
51
|
-
name: faraday_middleware
|
52
|
-
type: :runtime
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
39
|
none: false
|
56
40
|
requirements:
|
57
41
|
- - ~>
|
@@ -61,42 +45,43 @@ dependencies:
|
|
61
45
|
- 1
|
62
46
|
- 0
|
63
47
|
version: "1.0"
|
64
|
-
requirement: *
|
48
|
+
requirement: *id002
|
65
49
|
prerelease: false
|
66
50
|
name: multi_json
|
67
51
|
type: :runtime
|
68
52
|
- !ruby/object:Gem::Dependency
|
69
|
-
version_requirements: &
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
70
54
|
none: false
|
71
55
|
requirements:
|
72
56
|
- - ~>
|
73
57
|
- !ruby/object:Gem::Version
|
74
|
-
hash:
|
58
|
+
hash: 1
|
75
59
|
segments:
|
76
60
|
- 1
|
77
|
-
-
|
78
|
-
version: "1.
|
79
|
-
requirement: *
|
61
|
+
- 7
|
62
|
+
version: "1.7"
|
63
|
+
requirement: *id003
|
80
64
|
prerelease: false
|
81
65
|
name: json
|
82
66
|
type: :runtime
|
83
67
|
- !ruby/object:Gem::Dependency
|
84
|
-
version_requirements: &
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
85
69
|
none: false
|
86
70
|
requirements:
|
87
71
|
- - ~>
|
88
72
|
- !ruby/object:Gem::Version
|
89
|
-
hash:
|
73
|
+
hash: 19
|
90
74
|
segments:
|
75
|
+
- 1
|
76
|
+
- 1
|
91
77
|
- 0
|
92
|
-
|
93
|
-
|
94
|
-
requirement: *id005
|
78
|
+
version: 1.1.0
|
79
|
+
requirement: *id004
|
95
80
|
prerelease: false
|
96
81
|
name: yajl-ruby
|
97
82
|
type: :runtime
|
98
83
|
- !ruby/object:Gem::Dependency
|
99
|
-
version_requirements: &
|
84
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
100
85
|
none: false
|
101
86
|
requirements:
|
102
87
|
- - ">="
|
@@ -115,27 +100,12 @@ dependencies:
|
|
115
100
|
- 0
|
116
101
|
- 0
|
117
102
|
version: 4.0.0
|
118
|
-
requirement: *
|
103
|
+
requirement: *id005
|
119
104
|
prerelease: false
|
120
105
|
name: builder
|
121
106
|
type: :runtime
|
122
107
|
- !ruby/object:Gem::Dependency
|
123
|
-
version_requirements: &
|
124
|
-
none: false
|
125
|
-
requirements:
|
126
|
-
- - ~>
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
hash: 7
|
129
|
-
segments:
|
130
|
-
- 2
|
131
|
-
- 2
|
132
|
-
version: "2.2"
|
133
|
-
requirement: *id007
|
134
|
-
prerelease: false
|
135
|
-
name: addressable
|
136
|
-
type: :runtime
|
137
|
-
- !ruby/object:Gem::Dependency
|
138
|
-
version_requirements: &id008 !ruby/object:Gem::Requirement
|
108
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
139
109
|
none: false
|
140
110
|
requirements:
|
141
111
|
- - ">="
|
@@ -155,12 +125,12 @@ dependencies:
|
|
155
125
|
- 0
|
156
126
|
- 0
|
157
127
|
version: 4.0.0
|
158
|
-
requirement: *
|
128
|
+
requirement: *id006
|
159
129
|
prerelease: false
|
160
130
|
name: will_paginate
|
161
131
|
type: :runtime
|
162
132
|
- !ruby/object:Gem::Dependency
|
163
|
-
version_requirements: &
|
133
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
164
134
|
none: false
|
165
135
|
requirements:
|
166
136
|
- - ~>
|
@@ -171,12 +141,12 @@ dependencies:
|
|
171
141
|
- 9
|
172
142
|
- 2
|
173
143
|
version: 0.9.2
|
174
|
-
requirement: *
|
144
|
+
requirement: *id007
|
175
145
|
prerelease: false
|
176
146
|
name: rake
|
177
147
|
type: :development
|
178
148
|
- !ruby/object:Gem::Dependency
|
179
|
-
version_requirements: &
|
149
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
180
150
|
none: false
|
181
151
|
requirements:
|
182
152
|
- - ~>
|
@@ -187,12 +157,12 @@ dependencies:
|
|
187
157
|
- 8
|
188
158
|
- 0
|
189
159
|
version: 2.8.0
|
190
|
-
requirement: *
|
160
|
+
requirement: *id008
|
191
161
|
prerelease: false
|
192
162
|
name: rspec
|
193
163
|
type: :development
|
194
164
|
- !ruby/object:Gem::Dependency
|
195
|
-
version_requirements: &
|
165
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
196
166
|
none: false
|
197
167
|
requirements:
|
198
168
|
- - "="
|
@@ -203,12 +173,12 @@ dependencies:
|
|
203
173
|
- 7
|
204
174
|
- 5
|
205
175
|
version: 1.7.5
|
206
|
-
requirement: *
|
176
|
+
requirement: *id009
|
207
177
|
prerelease: false
|
208
178
|
name: webmock
|
209
179
|
type: :development
|
210
180
|
- !ruby/object:Gem::Dependency
|
211
|
-
version_requirements: &
|
181
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
212
182
|
none: false
|
213
183
|
requirements:
|
214
184
|
- - ~>
|
@@ -219,12 +189,12 @@ dependencies:
|
|
219
189
|
- 2
|
220
190
|
- 4
|
221
191
|
version: 0.2.4
|
222
|
-
requirement: *
|
192
|
+
requirement: *id010
|
223
193
|
prerelease: false
|
224
194
|
name: typhoeus
|
225
195
|
type: :development
|
226
196
|
- !ruby/object:Gem::Dependency
|
227
|
-
version_requirements: &
|
197
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
228
198
|
none: false
|
229
199
|
requirements:
|
230
200
|
- - ~>
|
@@ -235,12 +205,12 @@ dependencies:
|
|
235
205
|
- 6
|
236
206
|
- 3
|
237
207
|
version: 1.6.3
|
238
|
-
requirement: *
|
208
|
+
requirement: *id011
|
239
209
|
prerelease: false
|
240
210
|
name: ci_reporter
|
241
211
|
type: :development
|
242
212
|
- !ruby/object:Gem::Dependency
|
243
|
-
version_requirements: &
|
213
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
244
214
|
none: false
|
245
215
|
requirements:
|
246
216
|
- - ~>
|
@@ -251,12 +221,12 @@ dependencies:
|
|
251
221
|
- 9
|
252
222
|
- 9
|
253
223
|
version: 0.9.9
|
254
|
-
requirement: *
|
224
|
+
requirement: *id012
|
255
225
|
prerelease: false
|
256
226
|
name: rcov
|
257
227
|
type: :development
|
258
228
|
- !ruby/object:Gem::Dependency
|
259
|
-
version_requirements: &
|
229
|
+
version_requirements: &id013 !ruby/object:Gem::Requirement
|
260
230
|
none: false
|
261
231
|
requirements:
|
262
232
|
- - ~>
|
@@ -267,7 +237,7 @@ dependencies:
|
|
267
237
|
- 2
|
268
238
|
- 5
|
269
239
|
version: 0.2.5
|
270
|
-
requirement: *
|
240
|
+
requirement: *id013
|
271
241
|
prerelease: false
|
272
242
|
name: flexmls_gems
|
273
243
|
type: :development
|
@@ -288,7 +258,7 @@ files:
|
|
288
258
|
- VERSION
|
289
259
|
- bin/spark_api
|
290
260
|
- lib/spark_api/authentication/api_auth.rb
|
291
|
-
- lib/spark_api/authentication/oauth2_impl/
|
261
|
+
- lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb
|
292
262
|
- lib/spark_api/authentication/oauth2_impl/grant_type_base.rb
|
293
263
|
- lib/spark_api/authentication/oauth2_impl/password_provider.rb
|
294
264
|
- lib/spark_api/authentication/oauth2_impl/grant_type_code.rb
|
@@ -297,6 +267,7 @@ files:
|
|
297
267
|
- lib/spark_api/authentication/oauth2_impl/grant_type_password.rb
|
298
268
|
- lib/spark_api/authentication/oauth2.rb
|
299
269
|
- lib/spark_api/authentication/base_auth.rb
|
270
|
+
- lib/spark_api/faraday_middleware.rb
|
300
271
|
- lib/spark_api/client.rb
|
301
272
|
- lib/spark_api/primary_array.rb
|
302
273
|
- lib/spark_api/version.rb
|
@@ -335,7 +306,6 @@ files:
|
|
335
306
|
- lib/spark_api/cli/api_auth.rb
|
336
307
|
- lib/spark_api/cli/setup.rb
|
337
308
|
- lib/spark_api/cli/oauth2.rb
|
338
|
-
- lib/spark_api/faraday.rb
|
339
309
|
- lib/spark_api/request.rb
|
340
310
|
- lib/spark_api/options_hash.rb
|
341
311
|
- lib/spark_api/cli.rb
|
@@ -440,7 +410,6 @@ files:
|
|
440
410
|
- spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb
|
441
411
|
- spec/unit/spark_api/authentication/oauth2_spec.rb
|
442
412
|
- spec/unit/spark_api/authentication/api_auth_spec.rb
|
443
|
-
- spec/unit/spark_api/faraday_spec.rb
|
444
413
|
- spec/unit/spark_api/authentication_spec.rb
|
445
414
|
- spec/unit/spark_api/models/open_house_spec.rb
|
446
415
|
- spec/unit/spark_api/models/account_spec.rb
|
@@ -464,6 +433,7 @@ files:
|
|
464
433
|
- spec/unit/spark_api/models/tour_of_home_spec.rb
|
465
434
|
- spec/unit/spark_api/models/system_info_spec.rb
|
466
435
|
- spec/unit/spark_api/models/standard_fields_spec.rb
|
436
|
+
- spec/unit/spark_api/faraday_middleware_spec.rb
|
467
437
|
- spec/unit/spark_api/options_hash_spec.rb
|
468
438
|
- spec/unit/spark_api/paginate_spec.rb
|
469
439
|
- spec/unit/spark_api/primary_array_spec.rb
|
@@ -602,7 +572,6 @@ test_files:
|
|
602
572
|
- spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb
|
603
573
|
- spec/unit/spark_api/authentication/oauth2_spec.rb
|
604
574
|
- spec/unit/spark_api/authentication/api_auth_spec.rb
|
605
|
-
- spec/unit/spark_api/faraday_spec.rb
|
606
575
|
- spec/unit/spark_api/authentication_spec.rb
|
607
576
|
- spec/unit/spark_api/models/open_house_spec.rb
|
608
577
|
- spec/unit/spark_api/models/account_spec.rb
|
@@ -626,6 +595,7 @@ test_files:
|
|
626
595
|
- spec/unit/spark_api/models/tour_of_home_spec.rb
|
627
596
|
- spec/unit/spark_api/models/system_info_spec.rb
|
628
597
|
- spec/unit/spark_api/models/standard_fields_spec.rb
|
598
|
+
- spec/unit/spark_api/faraday_middleware_spec.rb
|
629
599
|
- spec/unit/spark_api/options_hash_spec.rb
|
630
600
|
- spec/unit/spark_api/paginate_spec.rb
|
631
601
|
- spec/unit/spark_api/primary_array_spec.rb
|
data/lib/spark_api/faraday.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module SparkApi
|
2
|
-
module FaradayExt
|
3
|
-
#=Spark API Faraday middleware
|
4
|
-
# HTTP Response after filter to package api responses and bubble up basic api errors.
|
5
|
-
class SparkMiddleware < Faraday::Response::ParseJson
|
6
|
-
include SparkApi::PaginateHelper
|
7
|
-
# Handles pretty much all the api response parsing and error handling. All responses that
|
8
|
-
# indicate a failure will raise a SparkApi::ClientError exception
|
9
|
-
def on_complete(finished_env)
|
10
|
-
body = parse(finished_env[:body])
|
11
|
-
SparkApi.logger.debug("Response Body: #{body.inspect}")
|
12
|
-
unless body.is_a?(Hash) && body.key?("D")
|
13
|
-
raise InvalidResponse, "The server response could not be understood"
|
14
|
-
end
|
15
|
-
response = ApiResponse.new body
|
16
|
-
paging = response.pagination
|
17
|
-
if paging.nil?
|
18
|
-
results = response
|
19
|
-
else
|
20
|
-
if finished_env[:url].query_values["_pagination"] == "count"
|
21
|
-
results = paging['TotalRows']
|
22
|
-
else
|
23
|
-
results = paginate_response(response, paging)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
case finished_env[:status]
|
27
|
-
when 400
|
28
|
-
hash = {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
29
|
-
|
30
|
-
# constraint violation
|
31
|
-
if response.code == 1053
|
32
|
-
details = body['D']['Details']
|
33
|
-
hash[:details] = details
|
34
|
-
end
|
35
|
-
raise BadResourceRequest,hash
|
36
|
-
when 401
|
37
|
-
# Handle the WWW-Authenticate Response Header Field if present. This can be returned by
|
38
|
-
# OAuth2 implementations and wouldn't hurt to log.
|
39
|
-
auth_header_error = finished_env[:request_headers]["WWW-Authenticate"]
|
40
|
-
SparkApi.logger.warn("Authentication error #{auth_header_error}") unless auth_header_error.nil?
|
41
|
-
raise PermissionDenied, {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
42
|
-
when 404
|
43
|
-
raise NotFound, {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
44
|
-
when 405
|
45
|
-
raise NotAllowed, {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
46
|
-
when 409
|
47
|
-
raise BadResourceRequest, {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
48
|
-
when 500
|
49
|
-
raise ClientError, {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
50
|
-
when 200..299
|
51
|
-
SparkApi.logger.debug("Success!")
|
52
|
-
else
|
53
|
-
raise ClientError, {:message => response.message, :code => response.code, :status => finished_env[:status]}
|
54
|
-
end
|
55
|
-
finished_env[:body] = results
|
56
|
-
end
|
57
|
-
|
58
|
-
def initialize(app)
|
59
|
-
super(app)
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|