spark_api 1.4.34 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/spark_api/authentication/api_auth.rb +5 -3
- data/lib/spark_api/authentication/oauth2.rb +2 -1
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +1 -1
- data/lib/spark_api/client.rb +2 -2
- data/lib/spark_api/models/media.rb +30 -0
- data/lib/spark_api/models/video.rb +108 -0
- data/lib/spark_api/models/virtual_tour.rb +16 -0
- data/lib/spark_api/models.rb +1 -0
- data/lib/spark_api/request.rb +17 -1
- data/lib/spark_api.rb +1 -0
- data/spec/spec_helper.rb +9 -4
- data/spec/unit/spark_api/authentication/api_auth_spec.rb +40 -22
- data/spec/unit/spark_api/authentication/base_auth_spec.rb +3 -3
- data/spec/unit/spark_api/authentication/oauth2_impl/faraday_middleware_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +1 -1
- data/spec/unit/spark_api/authentication/oauth2_impl/single_session_provider_spec.rb +2 -2
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +58 -40
- data/spec/unit/spark_api/authentication_spec.rb +2 -2
- data/spec/unit/spark_api/configuration/yaml_spec.rb +44 -44
- data/spec/unit/spark_api/configuration_spec.rb +56 -57
- data/spec/unit/spark_api/faraday_middleware_spec.rb +12 -12
- data/spec/unit/spark_api/models/account_spec.rb +20 -20
- data/spec/unit/spark_api/models/activity_spec.rb +5 -5
- data/spec/unit/spark_api/models/base_spec.rb +32 -32
- data/spec/unit/spark_api/models/concerns/destroyable_spec.rb +2 -2
- data/spec/unit/spark_api/models/concerns/savable_spec.rb +19 -19
- data/spec/unit/spark_api/models/connect_prefs_spec.rb +1 -1
- data/spec/unit/spark_api/models/constraint_spec.rb +1 -1
- data/spec/unit/spark_api/models/contact_spec.rb +50 -50
- data/spec/unit/spark_api/models/dirty_spec.rb +12 -12
- data/spec/unit/spark_api/models/document_spec.rb +3 -3
- data/spec/unit/spark_api/models/fields_spec.rb +17 -17
- data/spec/unit/spark_api/models/finders_spec.rb +7 -7
- data/spec/unit/spark_api/models/floplan_spec.rb +4 -4
- data/spec/unit/spark_api/models/listing_cart_spec.rb +46 -46
- data/spec/unit/spark_api/models/listing_meta_translations_spec.rb +6 -6
- data/spec/unit/spark_api/models/listing_spec.rb +91 -91
- data/spec/unit/spark_api/models/message_spec.rb +10 -10
- data/spec/unit/spark_api/models/note_spec.rb +10 -10
- data/spec/unit/spark_api/models/notification_spec.rb +6 -6
- data/spec/unit/spark_api/models/open_house_spec.rb +4 -4
- data/spec/unit/spark_api/models/photo_spec.rb +8 -8
- data/spec/unit/spark_api/models/portal_spec.rb +4 -4
- data/spec/unit/spark_api/models/property_types_spec.rb +5 -5
- data/spec/unit/spark_api/models/rental_calendar_spec.rb +13 -11
- data/spec/unit/spark_api/models/rule_spec.rb +2 -2
- data/spec/unit/spark_api/models/saved_search_spec.rb +33 -33
- data/spec/unit/spark_api/models/search_template/quick_search_spec.rb +5 -5
- data/spec/unit/spark_api/models/shared_listing_spec.rb +12 -12
- data/spec/unit/spark_api/models/sort_spec.rb +3 -3
- data/spec/unit/spark_api/models/standard_fields_spec.rb +12 -12
- data/spec/unit/spark_api/models/subresource_spec.rb +18 -18
- data/spec/unit/spark_api/models/system_info_spec.rb +7 -7
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +3 -3
- data/spec/unit/spark_api/models/video_spec.rb +9 -9
- data/spec/unit/spark_api/models/virtual_tour_spec.rb +7 -7
- data/spec/unit/spark_api/models/vow_account_spec.rb +8 -8
- data/spec/unit/spark_api/multi_client_spec.rb +14 -14
- data/spec/unit/spark_api/options_hash_spec.rb +4 -4
- data/spec/unit/spark_api/paginate_spec.rb +71 -71
- data/spec/unit/spark_api/primary_array_spec.rb +5 -5
- data/spec/unit/spark_api/request_spec.rb +79 -63
- data/spec/unit/spark_api_spec.rb +6 -6
- metadata +178 -248
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a99d333efb4d06b28966e72fde3baa3b0576ca30249baa555a1dbb613616d78
|
4
|
+
data.tar.gz: 9b83e6b6d097af7a0bd559121ab9bc702154d1a8afd39f2f9c59474946436c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f1a951daccd3cabed8ffb0fd3abbf3c7f0b2be7bdd55453e8a806341f0a4c06c0f5073cf5f2c1b07d3dcdd4bd265274d2441b91e268414eba4b52b01e72c51
|
7
|
+
data.tar.gz: 12b0fabf1ab8dab5d8871b4176ec6c2ec4b094a7713ab29e34f1c37f14a67e4aad69bb212a2bf94ff8d9d53298062010d13067054841a96b96a43bf268ff42b6
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Spark API
|
2
2
|
=====================
|
3
|
-
|
3
|
+
 
|
4
4
|
|
5
5
|
A Ruby wrapper for the Spark REST API. Loosely based on ActiveResource to provide models to interact with remote services.
|
6
6
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.3
|
@@ -62,7 +62,9 @@ module SparkApi
|
|
62
62
|
|
63
63
|
# Perform an HTTP request (no data)
|
64
64
|
def request(method, path, body, options)
|
65
|
-
escaped_path = URI.escape(path)
|
65
|
+
escaped_path = Addressable::URI.escape(path)
|
66
|
+
connection = @client.connection
|
67
|
+
connection.headers.merge!(options.delete(:override_headers) || {})
|
66
68
|
request_opts = {
|
67
69
|
:AuthToken => @session.auth_token
|
68
70
|
}
|
@@ -76,10 +78,10 @@ module SparkApi
|
|
76
78
|
request_path = "#{escaped_path}?#{build_url_parameters({"ApiSig"=>sig}.merge(request_opts))}"
|
77
79
|
SparkApi.logger.debug { "Request: #{request_path}" }
|
78
80
|
if body.nil?
|
79
|
-
response =
|
81
|
+
response = connection.send(method, request_path)
|
80
82
|
else
|
81
83
|
SparkApi.logger.debug { "Data: #{body}" }
|
82
|
-
response =
|
84
|
+
response = connection.send(method, request_path, body)
|
83
85
|
end
|
84
86
|
response
|
85
87
|
end
|
@@ -40,8 +40,9 @@ module SparkApi
|
|
40
40
|
|
41
41
|
# Perform an HTTP request (no data)
|
42
42
|
def request(method, path, body, options={})
|
43
|
-
escaped_path = URI.escape(path)
|
43
|
+
escaped_path = Addressable::URI.escape(path)
|
44
44
|
connection = @client.connection(true) # SSL Only!
|
45
|
+
connection.headers.merge!(options.delete(:override_headers) || {})
|
45
46
|
connection.headers.merge!(self.auth_header)
|
46
47
|
|
47
48
|
unless (@client.api_user.nil? || options[:ApiUser])
|
@@ -45,7 +45,7 @@ module SparkApi
|
|
45
45
|
response.expires_in = provider.session_timeout if response.expires_in.nil?
|
46
46
|
SparkApi.logger.debug { "[oauth2] New session created #{response}" }
|
47
47
|
response
|
48
|
-
rescue Faraday::
|
48
|
+
rescue Faraday::ConnectionFailed => e
|
49
49
|
if @client.ssl_verify && e.message =~ /certificate verify failed/
|
50
50
|
SparkApi.logger.error { SparkApi::Errors.ssl_verification_error }
|
51
51
|
end
|
data/lib/spark_api/client.rb
CHANGED
@@ -2,7 +2,7 @@ module SparkApi
|
|
2
2
|
# =API Client
|
3
3
|
# Main class to setup and run requests on the API. A default client is accessible globally as
|
4
4
|
# SparkApi::client if the global configuration has been set as well. Otherwise, this class may
|
5
|
-
# be
|
5
|
+
# be instantiated separately with the configuration information.
|
6
6
|
class Client
|
7
7
|
include Connection
|
8
8
|
include Authentication
|
@@ -21,7 +21,7 @@ module SparkApi
|
|
21
21
|
Configuration::VALID_OPTION_KEYS.each do |key|
|
22
22
|
send("#{key}=", options[key])
|
23
23
|
end
|
24
|
-
#
|
24
|
+
# Instantiate the authentication class passed in.
|
25
25
|
@authenticator = authentication_mode.send("new", self)
|
26
26
|
end
|
27
27
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SparkApi
|
2
|
+
module Models
|
3
|
+
module Media
|
4
|
+
# This module is effectively an interface and helper to combine common media
|
5
|
+
# actions and information. Media types (videos, virtual tours, etc)
|
6
|
+
# should include this module and implement the methods contained
|
7
|
+
|
8
|
+
def url
|
9
|
+
raise "Not Implemented"
|
10
|
+
end
|
11
|
+
|
12
|
+
def description
|
13
|
+
raise "Not Implemented"
|
14
|
+
end
|
15
|
+
|
16
|
+
def private?
|
17
|
+
attributes['Privacy'] == 'Private'
|
18
|
+
end
|
19
|
+
|
20
|
+
def public?
|
21
|
+
attributes['Privacy'] == 'Public'
|
22
|
+
end
|
23
|
+
|
24
|
+
def automatic?
|
25
|
+
attributes['Privacy'] == 'Automatic'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,7 +1,12 @@
|
|
1
|
+
require 'net/http'
|
1
2
|
module SparkApi
|
2
3
|
module Models
|
3
4
|
class Video < Base
|
4
5
|
extend Subresource
|
6
|
+
include Media
|
7
|
+
include Concerns::Savable,
|
8
|
+
Concerns::Destroyable
|
9
|
+
|
5
10
|
self.element_name = 'videos'
|
6
11
|
|
7
12
|
def branded?
|
@@ -11,6 +16,109 @@ module SparkApi
|
|
11
16
|
def unbranded?
|
12
17
|
attributes['Type'] == 'unbranded'
|
13
18
|
end
|
19
|
+
|
20
|
+
def url
|
21
|
+
attributes['ObjectHtml']
|
22
|
+
end
|
23
|
+
|
24
|
+
def description
|
25
|
+
attributes['Name']
|
26
|
+
end
|
27
|
+
|
28
|
+
# Some youtube URLS are youtu.be instead of youtube
|
29
|
+
SUPPORTED_VIDEO_TYPES = %w[vimeo youtu].freeze
|
30
|
+
|
31
|
+
def is_supported_type?
|
32
|
+
# Unfortunately there are so many formats of vimeo videos that we canot support all vimeo videos
|
33
|
+
# Therefore, we need to do a little more checking here and validate that we can get video codes out of the urls
|
34
|
+
(self.ObjectHtml.include?('youtu') && youtube_video_code.present?) || (self.ObjectHtml.include?('vimeo') && vimeo_video_code.present?)
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_valid_iframe?
|
38
|
+
self.ObjectHtml.include?('<iframe') && self.ObjectHtml.include?('</iframe>')
|
39
|
+
end
|
40
|
+
|
41
|
+
# gets the thumbnail to be shown on supported (Vimeo and Youtube) videos
|
42
|
+
# YouTube provides a predictable url for each video's images
|
43
|
+
# for Vimeo, a get request is necessary
|
44
|
+
def display_image
|
45
|
+
url = self.video_link
|
46
|
+
if url
|
47
|
+
if(url.include?('youtube'))
|
48
|
+
youtube_thumbnail_url
|
49
|
+
else
|
50
|
+
vimeo_thumbnail_url
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def video_link
|
56
|
+
return nil unless is_supported_type?
|
57
|
+
|
58
|
+
if self.ObjectHtml.include?('youtu')
|
59
|
+
youtube_link
|
60
|
+
elsif self.ObjectHtml.include?('vimeo')
|
61
|
+
vimeo_link
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def vimeo_video_code
|
68
|
+
html = self.ObjectHtml
|
69
|
+
if html.match(/(src=)('|")((https:)?\/\/player\.vimeo\.com\/video\/)/)
|
70
|
+
new_url = html.split(/(src=')|(src=")/)
|
71
|
+
if new_url[2]
|
72
|
+
html = new_url[2].split(/("|')/)[0]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
if html.match(/(?:.+?)?(player\.vimeo\.com|vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?))/)
|
76
|
+
code = html.split('/').last.split('?').first
|
77
|
+
# Vimeo Ids are always numerical
|
78
|
+
code.to_i.to_s === code ? code : nil
|
79
|
+
else
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# This if correctly embedded by the user is an embed
|
85
|
+
# If not, it could be pretty much anything
|
86
|
+
def youtube_video_code
|
87
|
+
html = self.ObjectHtml
|
88
|
+
if html.match(/(?:.+?)?(?:\/v\/|watch\/|\?v=|\&v=|youtu\.be\/|\/v=|^youtu\.be\/|embed\/|watch\%3Fv\%3D)([a-zA-Z0-9_-]{11})/) || html.match(/(iframe)(.*)(src=)('|")(https:\/\/www\.youtube\.com\/embed)/)
|
89
|
+
html.split(/([a-zA-Z0-9_-]{11})/)[1]
|
90
|
+
else
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def youtube_link
|
96
|
+
normalize_youtube_url
|
97
|
+
code = youtube_video_code
|
98
|
+
code ? "https://www.youtube.com/watch?v=#{code}" : nil
|
99
|
+
end
|
100
|
+
|
101
|
+
def vimeo_link
|
102
|
+
code = vimeo_video_code
|
103
|
+
code ? "https://vimeo.com/#{code}" : nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def youtube_thumbnail_url
|
107
|
+
code = youtube_video_code
|
108
|
+
code ? "https://i1.ytimg.com/vi/#{code}/hqdefault.jpg" : nil
|
109
|
+
end
|
110
|
+
|
111
|
+
def vimeo_thumbnail_url
|
112
|
+
# due to the rate limiting issue that surfaced shortly before launch,
|
113
|
+
# we will temporarily not return vimeo thumbnails until
|
114
|
+
# there is bandwidth to implement the solution in FLEX-9959
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def normalize_youtube_url
|
119
|
+
self.ObjectHtml.sub!('-nocookie', '')
|
120
|
+
end
|
121
|
+
|
14
122
|
end
|
15
123
|
end
|
16
124
|
end
|
@@ -2,6 +2,10 @@ module SparkApi
|
|
2
2
|
module Models
|
3
3
|
class VirtualTour < Base
|
4
4
|
extend Subresource
|
5
|
+
include Media
|
6
|
+
include Concerns::Savable,
|
7
|
+
Concerns::Destroyable
|
8
|
+
|
5
9
|
self.element_name="virtualtours"
|
6
10
|
|
7
11
|
|
@@ -13,6 +17,18 @@ module SparkApi
|
|
13
17
|
attributes["Type"] == "unbranded"
|
14
18
|
end
|
15
19
|
|
20
|
+
def url
|
21
|
+
attributes['Uri']
|
22
|
+
end
|
23
|
+
|
24
|
+
def description
|
25
|
+
attributes['Name']
|
26
|
+
end
|
27
|
+
|
28
|
+
def display_image
|
29
|
+
# Currently we have no universally good mechanism to get images for virtual tours
|
30
|
+
return nil
|
31
|
+
end
|
16
32
|
end
|
17
33
|
end
|
18
34
|
end
|
data/lib/spark_api/models.rb
CHANGED
@@ -25,6 +25,7 @@ require 'spark_api/models/listing'
|
|
25
25
|
require 'spark_api/models/listing_cart'
|
26
26
|
require 'spark_api/models/listing_meta_translations'
|
27
27
|
require 'spark_api/models/market_statistics'
|
28
|
+
require 'spark_api/models/media'
|
28
29
|
require 'spark_api/models/message'
|
29
30
|
require 'spark_api/models/news_feed_meta'
|
30
31
|
require 'spark_api/models/newsfeed'
|
data/lib/spark_api/request.rb
CHANGED
@@ -61,6 +61,22 @@ module SparkApi
|
|
61
61
|
unless authenticated?
|
62
62
|
authenticate
|
63
63
|
end
|
64
|
+
|
65
|
+
# Allow use of the X-HTTP-Method-Override header to disguise excessively
|
66
|
+
# large GET/DELETE/HEAD requests as POST requests.
|
67
|
+
if options[:http_method_override]
|
68
|
+
options = options.clone
|
69
|
+
options.delete(:http_method_override)
|
70
|
+
body = URI.encode_www_form(options)
|
71
|
+
options = {
|
72
|
+
override_headers: {
|
73
|
+
"X-HTTP-Method-Override" => method.to_s.upcase,
|
74
|
+
"Content-Type" => "application/x-www-form-urlencoded"
|
75
|
+
}
|
76
|
+
}
|
77
|
+
method = :post
|
78
|
+
end
|
79
|
+
|
64
80
|
attempts = 0
|
65
81
|
begin
|
66
82
|
request_opts = {}
|
@@ -99,7 +115,7 @@ module SparkApi
|
|
99
115
|
else
|
100
116
|
return response.body
|
101
117
|
end
|
102
|
-
rescue Faraday::
|
118
|
+
rescue Faraday::ConnectionFailed => e
|
103
119
|
if self.ssl_verify && e.message =~ /certificate verify failed/
|
104
120
|
SparkApi.logger.error { SparkApi::Errors.ssl_verification_error }
|
105
121
|
end
|
data/lib/spark_api.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,6 @@ end
|
|
11
11
|
|
12
12
|
require "rubygems"
|
13
13
|
require "rspec"
|
14
|
-
require 'rspec/autorun'
|
15
14
|
require 'webmock/rspec'
|
16
15
|
require "json"
|
17
16
|
require 'multi_json'
|
@@ -22,6 +21,13 @@ require path + '/spark_api'
|
|
22
21
|
|
23
22
|
require 'spark_api'
|
24
23
|
|
24
|
+
if ENV['COVERAGE'] == "on"
|
25
|
+
require 'simplecov'
|
26
|
+
require 'simplecov-rcov'
|
27
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
28
|
+
SimpleCov.start { add_filter %w(/vendor /spec /test) }
|
29
|
+
end
|
30
|
+
|
25
31
|
FileUtils.mkdir 'log' unless File.exists? 'log'
|
26
32
|
|
27
33
|
module SparkApi
|
@@ -48,17 +54,16 @@ end
|
|
48
54
|
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
49
55
|
|
50
56
|
RSpec.configure do |config|
|
51
|
-
|
57
|
+
|
52
58
|
config.include WebMock::API
|
53
59
|
config.include StubApiRequests
|
54
60
|
|
55
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
56
61
|
config.alias_example_to :on_get_it, :method => 'GET'
|
57
62
|
config.alias_example_to :on_put_it, :method => 'PUT'
|
58
63
|
config.alias_example_to :on_post_it, :method => 'POST'
|
59
64
|
config.alias_example_to :on_delete_it, :method => 'DELETE'
|
60
65
|
config.before(:all) { reset_config }
|
61
|
-
config.
|
66
|
+
config.color = true
|
62
67
|
end
|
63
68
|
|
64
69
|
def jruby?
|
@@ -4,15 +4,14 @@ describe SparkApi::Authentication::ApiAuth do
|
|
4
4
|
subject {SparkApi::Authentication::ApiAuth.new(nil) }
|
5
5
|
describe "build_param_hash" do
|
6
6
|
it "should return a blank string when passed nil" do
|
7
|
-
subject.build_param_string(nil).
|
7
|
+
expect(subject.build_param_string(nil)).to be_empty
|
8
8
|
end
|
9
9
|
it "should return a correct param string for one item" do
|
10
|
-
subject.build_param_string({:foo => "bar"}).
|
10
|
+
expect(subject.build_param_string({:foo => "bar"})).to match("foobar")
|
11
11
|
end
|
12
12
|
it "should alphabatize the param names by key first, then by value" do
|
13
|
-
subject.build_param_string({:zoo => "zar", :ooo => "car"}).
|
14
|
-
subject.build_param_string({:Akey => "aValue", :aNotherkey => "AnotherValue"}).
|
15
|
-
match "AkeyaValueaNotherkeyAnotherValue"
|
13
|
+
expect(subject.build_param_string({:zoo => "zar", :ooo => "car"})).to match("ooocarzoozar")
|
14
|
+
expect(subject.build_param_string({:Akey => "aValue", :aNotherkey => "AnotherValue"})).to match("AkeyaValueaNotherkeyAnotherValue")
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -33,7 +32,7 @@ describe SparkApi::Authentication::ApiAuth do
|
|
33
32
|
stub_request(:post, "https://api.sparkapi.com/#{SparkApi.version}/session").
|
34
33
|
with(:query => {:ApiKey => "my_key", :ApiSig => "c731cf2455fbc7a4ef937b2301108d7a"}).
|
35
34
|
to_return(:body => fixture("authentication_failure.json"), :status=>401)
|
36
|
-
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| e.status.
|
35
|
+
expect {subject.authenticate()}.to raise_error(SparkApi::ClientError){ |e| expect(e.status).to eq(401) }
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -41,16 +40,16 @@ describe SparkApi::Authentication::ApiAuth do
|
|
41
40
|
let(:session) { Object.new }
|
42
41
|
it "should return true when session is active" do
|
43
42
|
subject.session = session
|
44
|
-
session.
|
45
|
-
subject.authenticated
|
43
|
+
allow(session).to receive(:expired?) { false }
|
44
|
+
expect(subject.authenticated?).to eq(true)
|
46
45
|
end
|
47
46
|
it "should return false when session is expired" do
|
48
47
|
subject.session = session
|
49
|
-
session.
|
50
|
-
subject.authenticated
|
48
|
+
allow(session).to receive(:expired?) { true }
|
49
|
+
expect(subject.authenticated?).to eq(false)
|
51
50
|
end
|
52
51
|
it "should return false when session is uninitialized" do
|
53
|
-
subject.authenticated
|
52
|
+
expect(subject.authenticated?).to eq(false)
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
@@ -61,14 +60,14 @@ describe SparkApi::Authentication::ApiAuth do
|
|
61
60
|
it "should logout when there is an active session" do
|
62
61
|
logged_out = false
|
63
62
|
subject.session = session
|
64
|
-
client.
|
63
|
+
allow(client).to receive(:delete).with("/session/1234") { logged_out = true }
|
65
64
|
subject.logout
|
66
|
-
subject.session.
|
67
|
-
logged_out.
|
65
|
+
expect(subject.session).to eq(nil)
|
66
|
+
expect(logged_out).to eq(true)
|
68
67
|
end
|
69
68
|
it "should skip logging out when there is no active session information" do
|
70
|
-
client.
|
71
|
-
subject.logout.
|
69
|
+
allow(client).to receive(:delete) { raise "Should not be called" }
|
70
|
+
expect(subject.logout).to eq(nil)
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
@@ -98,7 +97,7 @@ describe SparkApi::Authentication::ApiAuth do
|
|
98
97
|
:AuthToken => "1234"}.merge(args)).
|
99
98
|
to_return(:body => fixture("listings/no_subresources.json"))
|
100
99
|
subject.session = session
|
101
|
-
subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status.
|
100
|
+
expect(subject.request(:get, "/#{SparkApi.version}/listings", nil, args).status).to eq(200)
|
102
101
|
end
|
103
102
|
it "should handle a post request" do
|
104
103
|
stub_auth_request
|
@@ -118,14 +117,33 @@ describe SparkApi::Authentication::ApiAuth do
|
|
118
117
|
}]}
|
119
118
|
}',
|
120
119
|
:status=>201)
|
121
|
-
subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status.
|
120
|
+
expect(subject.request(:post, "/#{SparkApi.version}/contacts", contact, args).status).to eq(201)
|
121
|
+
end
|
122
|
+
it "should incorporate any override_headers it is given while excluding them from the resulting request" do
|
123
|
+
stub_auth_request
|
124
|
+
args = {
|
125
|
+
override_headers: {
|
126
|
+
"Some-Header" => "Some-Value"
|
127
|
+
},
|
128
|
+
ApiUser: "foobar",
|
129
|
+
some_other_param: "some_other_value"
|
130
|
+
}
|
131
|
+
body = "somerequestbodytext"
|
132
|
+
stub_request(:post, "https://api.sparkapi.com/v1/someservice?ApiSig=856f5c036137c0cef5d4d223cd0f42be&ApiUser=foobar&AuthToken=1234&some_other_param=some_other_value").
|
133
|
+
with(body: "somerequestbodytext", headers: args[:override_headers]).
|
134
|
+
to_return(body: '{"D": {
|
135
|
+
"Success": true,
|
136
|
+
"Results": []
|
137
|
+
}',
|
138
|
+
status: 200)
|
139
|
+
expect(subject.request(:post, "/#{SparkApi.version}/someservice", body, args).status).to eq(200)
|
122
140
|
end
|
123
141
|
end
|
124
142
|
|
125
143
|
describe "sign" do
|
126
144
|
it "should sign the auth parameters correctly" do
|
127
145
|
sign_token = "my_secretApiKeymy_key"
|
128
|
-
subject.sign(sign_token).
|
146
|
+
expect(subject.sign(sign_token)).to eq("c731cf2455fbc7a4ef937b2301108d7a")
|
129
147
|
end
|
130
148
|
end
|
131
149
|
|
@@ -134,7 +152,7 @@ describe SparkApi::Authentication::ApiAuth do
|
|
134
152
|
subject {SparkApi::Authentication::ApiAuth.new(client) }
|
135
153
|
it "should fully sign the token" do
|
136
154
|
parms = {:AuthToken => "1234", :ApiUser => "CoolAsIce"}
|
137
|
-
subject.sign_token("/test", parms).
|
155
|
+
expect(subject.sign_token("/test", parms)).to eq("7bbe3384a8b64368357f8551cab271e3")
|
138
156
|
end
|
139
157
|
end
|
140
158
|
|
@@ -160,8 +178,8 @@ describe SparkApi::Authentication::ApiAuth do
|
|
160
178
|
to_return(:body => fixture('listings/with_documents.json'))
|
161
179
|
l = Listing.find('1234', :_expand => "Documents")
|
162
180
|
|
163
|
-
count.
|
164
|
-
SparkApi.client.session.expired
|
181
|
+
expect(count).to eq(2)
|
182
|
+
expect(SparkApi.client.session.expired?).to eq(false)
|
165
183
|
end
|
166
184
|
end
|
167
185
|
|