spark_api 1.0.2 → 1.0.4

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.
Files changed (90) hide show
  1. data/README.md +86 -3
  2. data/VERSION +1 -1
  3. data/lib/spark_api.rb +1 -0
  4. data/lib/spark_api/authentication/oauth2.rb +43 -2
  5. data/lib/spark_api/configuration/oauth2_configurable.rb +3 -1
  6. data/lib/spark_api/models.rb +1 -0
  7. data/lib/spark_api/models/listing.rb +17 -1
  8. data/lib/spark_api/models/rental_calendar.rb +26 -0
  9. data/lib/spark_api/options_hash.rb +18 -0
  10. data/script/combined_flow_example.rb +55 -0
  11. data/script/oauth2_example.rb +2 -2
  12. data/spec/fixtures/listings/rental_calendar.json +19 -0
  13. data/spec/fixtures/listings/with_rental_calendar.json +52 -0
  14. data/spec/unit/spark_api/authentication/oauth2_spec.rb +79 -1
  15. data/spec/unit/spark_api/models/listing_spec.rb +7 -0
  16. data/spec/unit/spark_api/models/rental_calendar_spec.rb +30 -0
  17. data/spec/unit/spark_api/options_hash_spec.rb +14 -0
  18. metadata +15 -96
  19. data/bin/spark_api~ +0 -8
  20. data/lib/spark_api/authentication/api_auth.rb~ +0 -104
  21. data/lib/spark_api/authentication/base_auth.rb~ +0 -47
  22. data/lib/spark_api/authentication/oauth2.rb~ +0 -199
  23. data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +0 -87
  24. data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +0 -49
  25. data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +0 -45
  26. data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +0 -36
  27. data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +0 -39
  28. data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +0 -25
  29. data/lib/spark_api/cli.rb~ +0 -158
  30. data/lib/spark_api/cli/api_auth.rb~ +0 -8
  31. data/lib/spark_api/cli/oauth2.rb~ +0 -14
  32. data/lib/spark_api/cli/setup.rb~ +0 -47
  33. data/lib/spark_api/configuration.rb~ +0 -54
  34. data/lib/spark_api/configuration/yaml.rb~ +0 -101
  35. data/lib/spark_api/faraday.rb~ +0 -64
  36. data/lib/spark_api/models.rb~ +0 -33
  37. data/lib/spark_api/models/account.rb~ +0 -115
  38. data/lib/spark_api/models/base.rb~ +0 -118
  39. data/lib/spark_api/models/connect_prefs.rb~ +0 -10
  40. data/lib/spark_api/models/constraint.rb~ +0 -16
  41. data/lib/spark_api/models/contact.rb~ +0 -49
  42. data/lib/spark_api/models/custom_fields.rb~ +0 -12
  43. data/lib/spark_api/models/document.rb~ +0 -11
  44. data/lib/spark_api/models/finders.rb~ +0 -45
  45. data/lib/spark_api/models/idx_link.rb~ +0 -47
  46. data/lib/spark_api/models/listing.rb~ +0 -197
  47. data/lib/spark_api/models/listing_cart.rb~ +0 -72
  48. data/lib/spark_api/models/market_statistics.rb~ +0 -33
  49. data/lib/spark_api/models/message.rb~ +0 -21
  50. data/lib/spark_api/models/note.rb~ +0 -41
  51. data/lib/spark_api/models/notification.rb~ +0 -42
  52. data/lib/spark_api/models/open_house.rb~ +0 -24
  53. data/lib/spark_api/models/photo.rb~ +0 -70
  54. data/lib/spark_api/models/property_types.rb~ +0 -7
  55. data/lib/spark_api/models/saved_search.rb~ +0 -16
  56. data/lib/spark_api/models/shared_listing.rb~ +0 -35
  57. data/lib/spark_api/models/standard_fields.rb~ +0 -50
  58. data/lib/spark_api/models/subresource.rb~ +0 -19
  59. data/lib/spark_api/models/system_info.rb~ +0 -14
  60. data/lib/spark_api/models/tour_of_home.rb~ +0 -24
  61. data/lib/spark_api/models/video.rb~ +0 -16
  62. data/lib/spark_api/models/virtual_tour.rb~ +0 -18
  63. data/lib/spark_api/multi_client.rb~ +0 -59
  64. data/lib/spark_api/paginate.rb~ +0 -109
  65. data/lib/spark_api/primary_array.rb~ +0 -29
  66. data/lib/spark_api/request.rb~ +0 -96
  67. data/lib/spark_api/response.rb~ +0 -70
  68. data/lib/spark_api/version.rb~ +0 -4
  69. data/script/console~ +0 -6
  70. data/script/example.rb~ +0 -27
  71. data/spec/unit/flexmls_api_spec.rb~ +0 -23
  72. data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +0 -169
  73. data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +0 -10
  74. data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +0 -10
  75. data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +0 -205
  76. data/spec/unit/spark_api/authentication_spec.rb~ +0 -38
  77. data/spec/unit/spark_api/configuration/yaml_spec.rb~ +0 -72
  78. data/spec/unit/spark_api/configuration_spec.rb~ +0 -122
  79. data/spec/unit/spark_api/faraday_spec.rb~ +0 -90
  80. data/spec/unit/spark_api/models/contact_spec.rb~ +0 -108
  81. data/spec/unit/spark_api/models/listing_cart_spec.rb~ +0 -127
  82. data/spec/unit/spark_api/models/listing_spec.rb~ +0 -320
  83. data/spec/unit/spark_api/models/message_spec.rb~ +0 -47
  84. data/spec/unit/spark_api/models/note_spec.rb~ +0 -63
  85. data/spec/unit/spark_api/models/notification_spec.rb~ +0 -62
  86. data/spec/unit/spark_api/models/shared_listing_spec.rb~ +0 -45
  87. data/spec/unit/spark_api/multi_client_spec.rb~ +0 -56
  88. data/spec/unit/spark_api/paginate_spec.rb~ +0 -224
  89. data/spec/unit/spark_api/primary_array_spec.rb~ +0 -41
  90. data/spec/unit/spark_api/request_spec.rb~ +0 -344
@@ -1,10 +0,0 @@
1
- require './spec/spec_helper'
2
- require './spec/oauth2_helper'
3
-
4
- describe FlexmlsApi::Authentication::OAuth2Impl::GrantTypeBase do
5
- subject { FlexmlsApi::Authentication::OAuth2Impl::GrantTypeBase }
6
- # Make sure the client boostraps the right plugin based on configuration.
7
- it "create should " do
8
- expect {subject.create(nil, InvalidAuth2Provider.new())}.to raise_error(FlexmlsApi::ClientError){ |e| e.message.should == "Unsupported grant type [not_a_real_type]" }
9
- end
10
- end
@@ -1,205 +0,0 @@
1
- require './spec/spec_helper'
2
- require './spec/oauth2_helper'
3
-
4
- describe FlexmlsApi::Authentication::OAuth2 do
5
- let(:provider) { TestOAuth2Provider.new() }
6
- let(:client) { FlexmlsApi::Client.new({:authentication_mode => FlexmlsApi::Authentication::OAuth2,:oauth2_provider => provider}) }
7
- subject {client.authenticator }
8
- # Make sure the client boostraps the right plugin based on configuration.
9
- describe "plugin" do
10
- it "should load the oauth2 authenticator" do
11
- client.authenticator.class.should eq(FlexmlsApi::Authentication::OAuth2)
12
- end
13
- end
14
- describe "authenticate" do
15
- it "should authenticate the api credentials" do
16
- stub_request(:post, provider.access_uri).
17
- with(:body =>
18
- '{"code":"my_code","client_secret":"example-password","client_id":"example-id","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback","grant_type":"authorization_code"}'
19
- ).
20
- to_return(:body => fixture("oauth2/access.json"), :status=>200)
21
- subject.authenticate.access_token.should eq("04u7h-4cc355-70k3n")
22
- subject.authenticate.expires_in.should eq(7200)
23
- end
24
-
25
- it "should raise an error when api credentials are invalid" do
26
- s=stub_request(:post, provider.access_uri).
27
- with(:body =>
28
- '{"code":"my_code","client_secret":"example-password","client_id":"example-id","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback","grant_type":"authorization_code"}'
29
- ).
30
- to_return(:body => fixture("oauth2/error.json"), :status=>400)
31
- expect {subject.authenticate()}.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
32
- end
33
-
34
- end
35
-
36
- describe "authenticated?" do
37
- let(:session) { Object.new }
38
- it "should return true when session is active" do
39
- subject.session = session
40
- session.stub(:expired?) { false }
41
- subject.authenticated?.should eq(true)
42
- end
43
- it "should return false when session is expired" do
44
- subject.session = session
45
- session.stub(:expired?) { true }
46
- subject.authenticated?.should eq(false)
47
- end
48
- it "should return false when session is uninitialized" do
49
- subject.authenticated?.should eq(false)
50
- end
51
- end
52
-
53
-
54
- describe "logout" do
55
- let(:session) { mock_oauth_session }
56
- it "should logout when there is an active session" do
57
- subject.session = session
58
- subject.logout
59
- subject.session.should eq(nil)
60
- end
61
- it "should skip logging out when there is no active session information" do
62
- client.stub(:delete) { raise "Should not be called" }
63
- subject.logout.should eq(nil)
64
- end
65
- end
66
-
67
- describe "request" do
68
- let(:session) { mock_oauth_session }
69
- it "should handle a get request" do
70
- subject.session = session
71
- args = {
72
- :_limit => '10',
73
- :_page => '1',
74
- :_pagination => '1'
75
- }
76
- c = stub_request(:get, "https://api.flexmls.com/#{FlexmlsApi.version}/listings").
77
- with(:query => args).
78
- to_return(:body => fixture("listings/no_subresources.json"))
79
- subject.session = session
80
- subject.request(:get, "/#{FlexmlsApi.version}/listings", nil, args).status.should eq(200)
81
- end
82
- it "should handle a post request" do
83
- subject.session = session
84
- args = {}
85
- contact = '{"D":{"Contacts":[{"DisplayName":"Contact Four","PrimaryEmail":"contact4@fbsdata.com"}]}}'
86
- stub_request(:post, "https://api.flexmls.com/#{FlexmlsApi.version}/contacts").
87
- with(:body => contact).
88
- to_return(:body => '{"D": {
89
- "Success": true,
90
- "Results": [
91
- {
92
- "ResourceUri":"/v1/contacts/20101230223226074204000000"
93
- }]}
94
- }',
95
- :status=>201)
96
- subject.request(:post, "/#{FlexmlsApi.version}/contacts", contact, args).status.should eq(201)
97
- end
98
- end
99
-
100
- context "with an expired session" do
101
- context "and a valid refresh token" do
102
- it "should reset the session and reauthenticate" do
103
- count = 0
104
- refresh_count = 0
105
- stub_request(:post, provider.access_uri).
106
- with(:body => '{"code":"my_code","client_secret":"example-password","client_id":"example-id","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback","grant_type":"authorization_code"}').
107
- to_return do
108
- count += 1
109
- {:body => fixture("oauth2/access_with_old_refresh.json"), :status=>200}
110
- end
111
- stub_request(:post, provider.access_uri).
112
- with(:body => '{"client_id":"example-id","client_secret":"example-password","grant_type":"refresh_token","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback","refresh_token":"0ld-r3fr35h-70k3n"}').
113
- to_return do
114
- refresh_count += 1
115
- {:body => fixture("oauth2/access_with_refresh.json"), :status=>200}
116
- end
117
- # Make sure the auth request goes out twice.
118
- # Fail the first time, but then return the correct value after reauthentication
119
- stub_request(:get, "https://api.flexmls.com/#{FlexmlsApi.version}/listings/1234").
120
- to_return(:body => fixture('errors/expired.json'), :status => 401).times(1).then.
121
- to_return(:body => fixture('listings/with_documents.json'))
122
- client.get("/listings/1234")
123
- count.should eq(1)
124
- refresh_count.should eq(1)
125
- client.session.expired?.should eq(false)
126
- end
127
- end
128
- context "and an invalid refresh token" do
129
- it "should reset the session and reauthenticate" do
130
- count = 0
131
- stub_request(:post, provider.access_uri).
132
- with(:body => '{"code":"my_code","client_secret":"example-password","client_id":"example-id","redirect_uri":"https://exampleapp.fbsdata.com/oauth-callback","grant_type":"authorization_code"}').
133
- to_return do
134
- count += 1
135
- {:body => fixture("oauth2/access.json"), :status=>200}
136
- end
137
- # Make sure the auth request goes out twice.
138
- # Fail the first time, but then return the correct value after reauthentication
139
- stub_request(:get, "https://api.flexmls.com/#{FlexmlsApi.version}/listings/1234").
140
- to_return(:body => fixture('errors/expired.json'), :status => 401).times(1).then.
141
- to_return(:body => fixture('listings/with_documents.json'))
142
-
143
- client.get("/listings/1234")
144
- count.should eq(2)
145
- client.session.expired?.should eq(false)
146
- end
147
- end
148
- end
149
- end
150
-
151
- describe FlexmlsApi::Authentication::BaseOAuth2Provider do
152
- context "session_timeout" do
153
- it "should provide a default" do
154
- subject.session_timeout.should eq(86400)
155
- end
156
- describe TestOAuth2Provider do
157
- subject { TestOAuth2Provider.new }
158
- it "should be able to override the session timeout" do
159
- subject.session_timeout.should eq(7200)
160
- end
161
- end
162
- end
163
- end
164
-
165
- describe "password authentication" do
166
- let(:provider) { TestCLIOAuth2Provider.new() }
167
- let(:client) { FlexmlsApi::Client.new({:authentication_mode => FlexmlsApi::Authentication::OAuth2,:oauth2_provider => provider}) }
168
- subject {client.authenticator }
169
- it "should authenticate the api credentials with username and password" do
170
- stub_request(:post, provider.access_uri).
171
- with(:body =>
172
- '{"username":"example-user","client_secret":"example-secret","client_id":"example-id","password":"example-password","grant_type":"password"}'
173
- ).
174
- to_return(:body => fixture("oauth2/access.json"), :status=>200)
175
- subject.authenticate.access_token.should eq("04u7h-4cc355-70k3n")
176
- subject.authenticate.expires_in.should eq(60)
177
- end
178
- end
179
- describe FlexmlsApi::Authentication::OAuth2Impl do
180
- it "should load a provider" do
181
- example = "FlexmlsApi::Authentication::OAuth2Impl::PasswordProvider"
182
- FlexmlsApi::Authentication::OAuth2Impl.load_provider(example,{}).class.to_s.should eq(example)
183
- prefix = "::#{example}"
184
- FlexmlsApi::Authentication::OAuth2Impl.load_provider(prefix,{}).class.to_s.should eq(example)
185
- bad_example = "Derp::Derp::Derp::DerpProvider"
186
- expect{FlexmlsApi::Authentication::OAuth2Impl.load_provider(bad_example,{}).class.to_s.should eq(bad_example)}.to raise_error(ArgumentError)
187
- end
188
-
189
- end
190
-
191
- describe FlexmlsApi::Authentication::OAuthSession do
192
- it "should serialize to json" do
193
- args = {
194
- "access_token" => "abc",
195
- "expires_in" => 3600,
196
- "refresh_token" => "123",
197
- "refresh_timeout" => 10000,
198
- "start_time" => "2012-01-01T00:00:00+00:00"
199
- }
200
- session = FlexmlsApi::Authentication::OAuthSession.new(args)
201
- session.start_time.should eq(DateTime.parse(args["start_time"]))
202
- JSON.parse(session.to_json).should eq(args)
203
-
204
- end
205
- end
@@ -1,38 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe FlexmlsApi::Authentication do
4
- before(:all) do
5
- FlexmlsApi.reset
6
- end
7
-
8
- after(:all) do
9
- reset_config
10
- end
11
-
12
- it "should give me a session object" do
13
- stub_auth_request
14
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/session/c401736bf3d3f754f07c04e460e09573").
15
- with(:query => {
16
- :ApiSig => "5596eff4550d74ec6802ac2d637ae5ae",
17
- :AuthToken => "c401736bf3d3f754f07c04e460e09573"
18
- }).
19
- to_return(:body => fixture("session.json"))
20
- client = FlexmlsApi.client
21
- stub_auth_request
22
- session = client.get "/session/c401736bf3d3f754f07c04e460e09573"
23
- session[0]["AuthToken"].should eq("c401736bf3d3f754f07c04e460e09573")
24
- end
25
- it "should delete a session" do
26
- stub_auth_request
27
- stub_request(:delete, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/session/c401736bf3d3f754f07c04e460e09573").
28
- with(:query => {
29
- :ApiSig => "5596eff4550d74ec6802ac2d637ae5ae",
30
- :AuthToken => "c401736bf3d3f754f07c04e460e09573"
31
- }).
32
- to_return(:body => fixture("success.json"))
33
- client = FlexmlsApi.client
34
- client.logout
35
- client.session.should eq(nil)
36
- end
37
-
38
- end
@@ -1,72 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe FlexmlsApi::Configuration::YamlConfig, "Yaml Config" do
4
- describe "api auth" do
5
- let(:api_file){ "spec/config/flexmls_api/test_key.yml" }
6
- it "should load a configured api key for development" do
7
- subject.stub(:env){ {} }
8
- subject.api_env.should eq("development")
9
- subject.load_file(api_file)
10
- subject.oauth2?.should eq(false)
11
- subject.api_key.should eq("demo_key")
12
- subject.api_secret.should eq("t3sts3cr3t")
13
- subject.endpoint.should eq("http://api.dev.flexmls.com")
14
- subject.name.should eq("test_key")
15
- subject.client_keys.keys.should =~ [:api_key, :api_secret, :endpoint]
16
- subject.oauth2_keys.keys.should eq([])
17
- end
18
- it "should load a configured api key for production" do
19
- subject.stub(:env){ {"FLEXMLS_API_ENV" => "production"} }
20
- subject.api_env.should eq("production")
21
- subject.load_file(api_file)
22
- subject.oauth2?.should eq(false)
23
- subject.api_key.should eq("prod_demo_key")
24
- subject.api_secret.should eq("prod_t3sts3cr3t")
25
- subject.endpoint.should eq("http://api.test.flexmls.com")
26
- end
27
- it "should raise an error for a bad configuration" do
28
- subject.stub(:env){ {} }
29
- expect { subject.load_file("spec/config/flexmls_api/some_random_key.yml")}.to raise_error
30
- subject.stub(:env){ {"RAILS_ENV" => "fake_env"} }
31
- expect { subject.load_file(api_file)}.to raise_error
32
- end
33
- end
34
- describe "oauth2" do
35
- let(:oauth2_file){ "spec/config/flexmls_api/test_oauth.yml" }
36
- it "should load a configured api key for development" do
37
- subject.stub(:env){ {} }
38
- subject.api_env.should eq("development")
39
- subject.load_file(oauth2_file)
40
- subject.oauth2?.should eq(true)
41
- subject.authorization_uri.should eq("https://dev.flexmls.com/r/login/")
42
- subject.access_uri.should eq("https://api.dev.flexmls.com/v1/oauth2/grant")
43
- subject.redirect_uri.should eq("http://localhost/oauth2/callback")
44
- subject.client_id.should eq("developmentid124nj4qu3pua")
45
- subject.client_secret.should eq("developmentsecret4orkp29f")
46
- subject.endpoint.should eq("http://api.dev.flexmls.com")
47
- subject.oauth2_provider.should eq("FlexmlsApi::TestOAuth2Provider")
48
- subject.name.should eq("test_oauth")
49
- subject.client_keys.keys.should =~ [:endpoint, :oauth2_provider]
50
- subject.oauth2_keys.keys.should =~ [:authorization_uri, :client_id, :access_uri, :client_secret, :redirect_uri]
51
- end
52
- it "should load a configured api key for production" do
53
- subject.stub(:env){ {"FLEXMLS_API_ENV" => "production"} }
54
- subject.api_env.should eq("production")
55
- subject.load_file(oauth2_file)
56
- subject.oauth2?.should eq(true)
57
- subject.authorization_uri.should eq("https://www.flexmls.com/r/login/")
58
- subject.access_uri.should eq("https://api.flexmls.com/v1/oauth2/grant")
59
- subject.redirect_uri.should eq("http://localhost/oauth2/callback")
60
- subject.client_id.should eq("production1id124nj4qu3pua")
61
- subject.client_secret.should eq("productionsecret4orkp29fv")
62
- subject.endpoint.should eq("http://api.flexmls.com")
63
- subject.oauth2_provider.should eq(subject.class::DEFAULT_OAUTH2_PROVIDER)
64
- subject.name.should eq("test_oauth")
65
- end
66
-
67
- it "should list available keys" do
68
- FlexmlsApi::Configuration::YamlConfig.stub(:config_path) { "spec/config/flexmls_api" }
69
- subject.class.config_keys.should =~ ["test_key", "test_oauth"]
70
- end
71
- end
72
- end
@@ -1,122 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- describe FlexmlsApi::Client, "Client config" do
4
- after(:all) do
5
- reset_config
6
- end
7
-
8
- describe "default settings" do
9
- it "should return the proper defaults when called with no arguments" do
10
- FlexmlsApi.api_key.should be_nil
11
- FlexmlsApi.api_secret.should be_nil
12
- FlexmlsApi.version.should match("v1")
13
- FlexmlsApi.endpoint.should match("api.flexmls.com")
14
- FlexmlsApi.user_agent.should match(/flexmls API Ruby Gem .*/)
15
- FlexmlsApi.api_key = "my_api_key"
16
- FlexmlsApi.api_key.should match("my_api_key")
17
- end
18
- end
19
-
20
- describe "instance config" do
21
- it "should return a properly configured client" do
22
- client = FlexmlsApi::Client.new(:api_key => "key_of_wade",
23
- :api_secret => "TopSecret",
24
- :api_user => "1234",
25
- :endpoint => "http://api.wade.dev.fbsdata.com")
26
-
27
- client.api_key.should match("key_of_wade")
28
- client.api_secret.should match("TopSecret")
29
- client.api_user.should match("1234")
30
- client.endpoint.should match("http://api.wade.dev.fbsdata.com")
31
- client.version.should match("v1")
32
- end
33
- end
34
-
35
- describe "block config" do
36
- it "should correctly set up the client" do
37
- FlexmlsApi.configure do |config|
38
- config.api_key = "my_key"
39
- config.api_secret = "my_secret"
40
- config.api_user = "1234"
41
- config.version = "veleventy"
42
- config.endpoint = "test.api.flexmls.com"
43
- config.user_agent = "my useragent"
44
- end
45
-
46
- FlexmlsApi.api_key.should match("my_key")
47
- FlexmlsApi.api_secret.should match("my_secret")
48
- FlexmlsApi.api_user.should match("1234")
49
- FlexmlsApi.version.should match("veleventy")
50
- FlexmlsApi.endpoint.should match("test.api.flexmls.com")
51
- FlexmlsApi.user_agent.should match("my useragent")
52
-
53
- end
54
-
55
- it "should reset" do
56
- FlexmlsApi.configure do |config|
57
- config.api_key = "my_key"
58
- config.api_secret = "my_secret"
59
- config.version = "veleventy"
60
- config.endpoint = "test.api.flexmls.com"
61
- config.user_agent = "my useragent"
62
- end
63
-
64
- FlexmlsApi.api_key.should match("my_key")
65
- FlexmlsApi.reset
66
- FlexmlsApi.api_key.should == FlexmlsApi::Configuration::DEFAULT_API_KEY
67
-
68
- end
69
- end
70
-
71
- describe "connections" do
72
- it "should use http by default" do
73
- stub_auth_request
74
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/connections").
75
- with(:query => {
76
- :ApiSig => "951e5ba0496b0758356d3cc7676f8b21",
77
- :AuthToken => "c401736bf3d3f754f07c04e460e09573"
78
- }).
79
- to_return(:body => '{"D":{"Success": true,"Results": [{"SSL":false}]}}')
80
-
81
- FlexmlsApi.client.get('/connections')[0]["SSL"].should eq(false)
82
- end
83
-
84
- it "should use https when ssl is enabled" do
85
- stub_auth_request
86
- stub_request(:get, "https://api.flexmls.com/#{FlexmlsApi.version}/connections").
87
- with(:query => {
88
- :ApiSig => "951e5ba0496b0758356d3cc7676f8b21",
89
- :AuthToken => "c401736bf3d3f754f07c04e460e09573"
90
- }).
91
- to_return(:body => '{"D":{"Success": true,"Results": [{"SSL":true}]}}')
92
-
93
- c = FlexmlsApi::Client.new(:endpoint => "https://api.flexmls.com", :ssl => true)
94
- c.get('/connections')[0]["SSL"].should eq(true)
95
- end
96
-
97
- it "should have correct headers based on configuration" do
98
- stub_auth_request
99
- stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/headers").
100
- with(:query => {
101
- :ApiSig => "6f0cfef263e0bfe7a9ae1f60063a8ad9",
102
- :AuthToken => "c401736bf3d3f754f07c04e460e09573"
103
- }).
104
- to_return(:body => '{"D":{"Success": true,"Results": []}}')
105
- FlexmlsApi.reset
106
- FlexmlsApi.configure do |config|
107
- config.user_agent = "my useragent"
108
- end
109
- FlexmlsApi.client.get '/headers'
110
- WebMock.should have_requested(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/headers?ApiSig=6f0cfef263e0bfe7a9ae1f60063a8ad9&AuthToken=c401736bf3d3f754f07c04e460e09573").
111
- with(:headers => {
112
- 'User-Agent' => FlexmlsApi::Configuration::DEFAULT_USER_AGENT,
113
- FlexmlsApi::Configuration::X_FLEXMLS_API_USER_AGENT => "my useragent",
114
- 'Accept'=>'application/json',
115
- 'Content-Type'=>'application/json'
116
- })
117
- end
118
-
119
- end
120
-
121
- end
122
-