spark_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +139 -0
- data/LICENSE +14 -0
- data/README.md +153 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/bin/spark_api +8 -0
- data/bin/spark_api~ +8 -0
- data/lib/spark_api.rb +46 -0
- data/lib/spark_api/authentication.rb +55 -0
- data/lib/spark_api/authentication/api_auth.rb +104 -0
- data/lib/spark_api/authentication/api_auth.rb~ +104 -0
- data/lib/spark_api/authentication/base_auth.rb +47 -0
- data/lib/spark_api/authentication/base_auth.rb~ +47 -0
- data/lib/spark_api/authentication/oauth2.rb +198 -0
- data/lib/spark_api/authentication/oauth2.rb~ +199 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +87 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +87 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb +48 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +49 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb +44 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +45 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb +35 -0
- data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +36 -0
- data/lib/spark_api/authentication/oauth2_impl/middleware.rb +38 -0
- data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +39 -0
- data/lib/spark_api/authentication/oauth2_impl/password_provider.rb +24 -0
- data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +25 -0
- data/lib/spark_api/cli.rb +158 -0
- data/lib/spark_api/cli.rb~ +158 -0
- data/lib/spark_api/cli/api_auth.rb +8 -0
- data/lib/spark_api/cli/api_auth.rb~ +8 -0
- data/lib/spark_api/cli/oauth2.rb +14 -0
- data/lib/spark_api/cli/oauth2.rb~ +14 -0
- data/lib/spark_api/cli/setup.rb +47 -0
- data/lib/spark_api/cli/setup.rb~ +47 -0
- data/lib/spark_api/client.rb +27 -0
- data/lib/spark_api/configuration.rb +54 -0
- data/lib/spark_api/configuration.rb~ +54 -0
- data/lib/spark_api/configuration/yaml.rb +101 -0
- data/lib/spark_api/configuration/yaml.rb~ +101 -0
- data/lib/spark_api/connection.rb +42 -0
- data/lib/spark_api/faraday.rb +64 -0
- data/lib/spark_api/faraday.rb~ +64 -0
- data/lib/spark_api/models.rb +33 -0
- data/lib/spark_api/models.rb~ +33 -0
- data/lib/spark_api/models/account.rb +115 -0
- data/lib/spark_api/models/account.rb~ +115 -0
- data/lib/spark_api/models/base.rb +118 -0
- data/lib/spark_api/models/base.rb~ +118 -0
- data/lib/spark_api/models/connect_prefs.rb +10 -0
- data/lib/spark_api/models/connect_prefs.rb~ +10 -0
- data/lib/spark_api/models/constraint.rb +16 -0
- data/lib/spark_api/models/constraint.rb~ +16 -0
- data/lib/spark_api/models/contact.rb +49 -0
- data/lib/spark_api/models/contact.rb~ +49 -0
- data/lib/spark_api/models/custom_fields.rb +12 -0
- data/lib/spark_api/models/custom_fields.rb~ +12 -0
- data/lib/spark_api/models/document.rb +11 -0
- data/lib/spark_api/models/document.rb~ +11 -0
- data/lib/spark_api/models/finders.rb +45 -0
- data/lib/spark_api/models/finders.rb~ +45 -0
- data/lib/spark_api/models/idx_link.rb +47 -0
- data/lib/spark_api/models/idx_link.rb~ +47 -0
- data/lib/spark_api/models/listing.rb +197 -0
- data/lib/spark_api/models/listing.rb~ +197 -0
- data/lib/spark_api/models/listing_cart.rb +72 -0
- data/lib/spark_api/models/listing_cart.rb~ +72 -0
- data/lib/spark_api/models/market_statistics.rb +33 -0
- data/lib/spark_api/models/market_statistics.rb~ +33 -0
- data/lib/spark_api/models/message.rb +21 -0
- data/lib/spark_api/models/message.rb~ +21 -0
- data/lib/spark_api/models/note.rb +41 -0
- data/lib/spark_api/models/note.rb~ +41 -0
- data/lib/spark_api/models/notification.rb +42 -0
- data/lib/spark_api/models/notification.rb~ +42 -0
- data/lib/spark_api/models/open_house.rb +24 -0
- data/lib/spark_api/models/open_house.rb~ +24 -0
- data/lib/spark_api/models/photo.rb +70 -0
- data/lib/spark_api/models/photo.rb~ +70 -0
- data/lib/spark_api/models/property_types.rb +7 -0
- data/lib/spark_api/models/property_types.rb~ +7 -0
- data/lib/spark_api/models/saved_search.rb +16 -0
- data/lib/spark_api/models/saved_search.rb~ +16 -0
- data/lib/spark_api/models/shared_listing.rb +35 -0
- data/lib/spark_api/models/shared_listing.rb~ +35 -0
- data/lib/spark_api/models/standard_fields.rb +50 -0
- data/lib/spark_api/models/standard_fields.rb~ +50 -0
- data/lib/spark_api/models/subresource.rb +19 -0
- data/lib/spark_api/models/subresource.rb~ +19 -0
- data/lib/spark_api/models/system_info.rb +14 -0
- data/lib/spark_api/models/system_info.rb~ +14 -0
- data/lib/spark_api/models/tour_of_home.rb +24 -0
- data/lib/spark_api/models/tour_of_home.rb~ +24 -0
- data/lib/spark_api/models/video.rb +16 -0
- data/lib/spark_api/models/video.rb~ +16 -0
- data/lib/spark_api/models/virtual_tour.rb +18 -0
- data/lib/spark_api/models/virtual_tour.rb~ +18 -0
- data/lib/spark_api/multi_client.rb +59 -0
- data/lib/spark_api/multi_client.rb~ +59 -0
- data/lib/spark_api/paginate.rb +109 -0
- data/lib/spark_api/paginate.rb~ +109 -0
- data/lib/spark_api/primary_array.rb +29 -0
- data/lib/spark_api/primary_array.rb~ +29 -0
- data/lib/spark_api/request.rb +96 -0
- data/lib/spark_api/request.rb~ +96 -0
- data/lib/spark_api/response.rb +70 -0
- data/lib/spark_api/response.rb~ +70 -0
- data/lib/spark_api/version.rb +4 -0
- data/lib/spark_api/version.rb~ +4 -0
- data/script/console +6 -0
- data/script/console~ +6 -0
- data/script/example.rb +27 -0
- data/script/example.rb~ +27 -0
- data/spec/fixtures/accounts/all.json +160 -0
- data/spec/fixtures/accounts/my.json +74 -0
- data/spec/fixtures/accounts/my_portal.json +20 -0
- data/spec/fixtures/accounts/my_put.json +5 -0
- data/spec/fixtures/accounts/my_save.json +5 -0
- data/spec/fixtures/accounts/office.json +142 -0
- data/spec/fixtures/accounts/password_save.json +6 -0
- data/spec/fixtures/authentication_failure.json +7 -0
- data/spec/fixtures/base.json +13 -0
- data/spec/fixtures/contacts/contacts.json +28 -0
- data/spec/fixtures/contacts/my.json +19 -0
- data/spec/fixtures/contacts/new.json +11 -0
- data/spec/fixtures/contacts/new_empty.json +8 -0
- data/spec/fixtures/contacts/new_notify.json +11 -0
- data/spec/fixtures/contacts/post.json +10 -0
- data/spec/fixtures/contacts/tags.json +11 -0
- data/spec/fixtures/count.json +10 -0
- data/spec/fixtures/empty.json +3 -0
- data/spec/fixtures/errors/expired.json +7 -0
- data/spec/fixtures/errors/failure.json +5 -0
- data/spec/fixtures/errors/failure_with_constraint.json +17 -0
- data/spec/fixtures/errors/failure_with_msg.json +7 -0
- data/spec/fixtures/generic_delete.json +1 -0
- data/spec/fixtures/generic_failure.json +5 -0
- data/spec/fixtures/listing_carts/add_listing.json +13 -0
- data/spec/fixtures/listing_carts/add_listing_post.json +5 -0
- data/spec/fixtures/listing_carts/empty.json +5 -0
- data/spec/fixtures/listing_carts/listing_cart.json +19 -0
- data/spec/fixtures/listing_carts/new.json +12 -0
- data/spec/fixtures/listing_carts/post.json +10 -0
- data/spec/fixtures/listing_carts/remove_listing.json +13 -0
- data/spec/fixtures/listings/constraints.json +18 -0
- data/spec/fixtures/listings/constraints_with_pagination.json +24 -0
- data/spec/fixtures/listings/document_index.json +19 -0
- data/spec/fixtures/listings/multiple.json +69 -0
- data/spec/fixtures/listings/no_subresources.json +38 -0
- data/spec/fixtures/listings/open_houses.json +21 -0
- data/spec/fixtures/listings/photos/index.json +469 -0
- data/spec/fixtures/listings/photos/new.json +12 -0
- data/spec/fixtures/listings/photos/post.json +20 -0
- data/spec/fixtures/listings/put.json +5 -0
- data/spec/fixtures/listings/put_expiration_date.json +5 -0
- data/spec/fixtures/listings/saved_search.json +17 -0
- data/spec/fixtures/listings/shared_listing_get.json +14 -0
- data/spec/fixtures/listings/shared_listing_new.json +9 -0
- data/spec/fixtures/listings/shared_listing_post.json +10 -0
- data/spec/fixtures/listings/tour_of_homes.json +23 -0
- data/spec/fixtures/listings/videos_index.json +18 -0
- data/spec/fixtures/listings/virtual_tours_index.json +42 -0
- data/spec/fixtures/listings/with_documents.json +52 -0
- data/spec/fixtures/listings/with_permissions.json +44 -0
- data/spec/fixtures/listings/with_photos.json +110 -0
- data/spec/fixtures/listings/with_supplement.json +39 -0
- data/spec/fixtures/listings/with_videos.json +54 -0
- data/spec/fixtures/listings/with_vtour.json +48 -0
- data/spec/fixtures/logo_fbs.png +0 -0
- data/spec/fixtures/messages/new.json +14 -0
- data/spec/fixtures/messages/new_empty.json +7 -0
- data/spec/fixtures/messages/new_with_recipients.json +15 -0
- data/spec/fixtures/messages/post.json +5 -0
- data/spec/fixtures/notes/add.json +11 -0
- data/spec/fixtures/notes/agent_shared.json +11 -0
- data/spec/fixtures/notes/agent_shared_empty.json +7 -0
- data/spec/fixtures/notes/new.json +5 -0
- data/spec/fixtures/notifications/mark_read.json +1 -0
- data/spec/fixtures/notifications/new.json +8 -0
- data/spec/fixtures/notifications/new_empty.json +7 -0
- data/spec/fixtures/notifications/notifications.json +43 -0
- data/spec/fixtures/notifications/post.json +10 -0
- data/spec/fixtures/notifications/unread.json +10 -0
- data/spec/fixtures/oauth2/access.json +3 -0
- data/spec/fixtures/oauth2/access_with_old_refresh.json +5 -0
- data/spec/fixtures/oauth2/access_with_refresh.json +5 -0
- data/spec/fixtures/oauth2/authorization_code_body.json +7 -0
- data/spec/fixtures/oauth2/error.json +3 -0
- data/spec/fixtures/oauth2/password_body.json +7 -0
- data/spec/fixtures/oauth2/refresh_body.json +7 -0
- data/spec/fixtures/oauth2_error.json +3 -0
- data/spec/fixtures/property_types/property_types.json +31 -0
- data/spec/fixtures/session.json +10 -0
- data/spec/fixtures/standardfields/city.json +1031 -0
- data/spec/fixtures/standardfields/nearby.json +53 -0
- data/spec/fixtures/standardfields/standardfields.json +188 -0
- data/spec/fixtures/standardfields/stateorprovince.json +36 -0
- data/spec/fixtures/success.json +5 -0
- data/spec/json_helper.rb +76 -0
- data/spec/mock_helper.rb +124 -0
- data/spec/oauth2_helper.rb +68 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/unit/flexmls_api_spec.rb~ +23 -0
- data/spec/unit/spark_api/authentication/api_auth_spec.rb +169 -0
- data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +169 -0
- data/spec/unit/spark_api/authentication/base_auth_spec.rb +10 -0
- data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +10 -0
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +10 -0
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +10 -0
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +205 -0
- data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +205 -0
- data/spec/unit/spark_api/authentication_spec.rb +38 -0
- data/spec/unit/spark_api/authentication_spec.rb~ +38 -0
- data/spec/unit/spark_api/configuration/yaml_spec.rb +72 -0
- data/spec/unit/spark_api/configuration/yaml_spec.rb~ +72 -0
- data/spec/unit/spark_api/configuration_spec.rb +122 -0
- data/spec/unit/spark_api/configuration_spec.rb~ +122 -0
- data/spec/unit/spark_api/faraday_spec.rb +90 -0
- data/spec/unit/spark_api/faraday_spec.rb~ +90 -0
- data/spec/unit/spark_api/models/account_spec.rb +176 -0
- data/spec/unit/spark_api/models/base_spec.rb +106 -0
- data/spec/unit/spark_api/models/connect_prefs_spec.rb +9 -0
- data/spec/unit/spark_api/models/constraint_spec.rb +19 -0
- data/spec/unit/spark_api/models/contact_spec.rb +108 -0
- data/spec/unit/spark_api/models/contact_spec.rb~ +108 -0
- data/spec/unit/spark_api/models/document_spec.rb +32 -0
- data/spec/unit/spark_api/models/listing_cart_spec.rb +127 -0
- data/spec/unit/spark_api/models/listing_cart_spec.rb~ +127 -0
- data/spec/unit/spark_api/models/listing_spec.rb +320 -0
- data/spec/unit/spark_api/models/listing_spec.rb~ +320 -0
- data/spec/unit/spark_api/models/message_spec.rb +47 -0
- data/spec/unit/spark_api/models/message_spec.rb~ +47 -0
- data/spec/unit/spark_api/models/note_spec.rb +63 -0
- data/spec/unit/spark_api/models/note_spec.rb~ +63 -0
- data/spec/unit/spark_api/models/notification_spec.rb +62 -0
- data/spec/unit/spark_api/models/notification_spec.rb~ +62 -0
- data/spec/unit/spark_api/models/open_house_spec.rb +39 -0
- data/spec/unit/spark_api/models/photo_spec.rb +92 -0
- data/spec/unit/spark_api/models/property_types_spec.rb +33 -0
- data/spec/unit/spark_api/models/saved_search_spec.rb +40 -0
- data/spec/unit/spark_api/models/shared_listing_spec.rb +45 -0
- data/spec/unit/spark_api/models/shared_listing_spec.rb~ +45 -0
- data/spec/unit/spark_api/models/standard_fields_spec.rb +60 -0
- data/spec/unit/spark_api/models/system_info_spec.rb +83 -0
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +44 -0
- data/spec/unit/spark_api/models/video_spec.rb +36 -0
- data/spec/unit/spark_api/models/virtual_tour_spec.rb +44 -0
- data/spec/unit/spark_api/multi_client_spec.rb +56 -0
- data/spec/unit/spark_api/multi_client_spec.rb~ +56 -0
- data/spec/unit/spark_api/paginate_spec.rb +224 -0
- data/spec/unit/spark_api/paginate_spec.rb~ +224 -0
- data/spec/unit/spark_api/primary_array_spec.rb +41 -0
- data/spec/unit/spark_api/primary_array_spec.rb~ +41 -0
- data/spec/unit/spark_api/request_spec.rb +344 -0
- data/spec/unit/spark_api/request_spec.rb~ +344 -0
- data/spec/unit/spark_api_spec.rb +23 -0
- metadata +725 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe SparkApi::Authentication do
|
4
|
+
before(:all) do
|
5
|
+
SparkApi.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, "#{SparkApi.endpoint}/#{SparkApi.version}/session/c401736bf3d3f754f07c04e460e09573").
|
15
|
+
with(:query => {
|
16
|
+
:ApiSig => "5596eff4550d74ec6802ac2d637ae5ae",
|
17
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573"
|
18
|
+
}).
|
19
|
+
to_return(:body => fixture("session.json"))
|
20
|
+
client = SparkApi.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, "#{SparkApi.endpoint}/#{SparkApi.version}/session/c401736bf3d3f754f07c04e460e09573").
|
28
|
+
with(:query => {
|
29
|
+
:ApiSig => "5596eff4550d74ec6802ac2d637ae5ae",
|
30
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573"
|
31
|
+
}).
|
32
|
+
to_return(:body => fixture("success.json"))
|
33
|
+
client = SparkApi.client
|
34
|
+
client.logout
|
35
|
+
client.session.should eq(nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe SparkApi::Configuration::YamlConfig, "Yaml Config" do
|
4
|
+
describe "api auth" do
|
5
|
+
let(:api_file){ "spec/config/spark_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("https://developers.sparkapi.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){ {"SPARK_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("https://api.sparkapi.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/spark_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/spark_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://developers.sparkplatform.com/oauth2")
|
42
|
+
subject.access_uri.should eq("https://developers.sparkapi.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("https://developers.sparkapi.com")
|
47
|
+
subject.oauth2_provider.should eq("SparkApi::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){ {"SPARK_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://sparkplatform.com/oauth2")
|
58
|
+
subject.access_uri.should eq("https://api.sparkapi.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("https://api.sparkapi.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
|
+
SparkApi::Configuration::YamlConfig.stub(:config_path) { "spec/config/spark_api" }
|
69
|
+
subject.class.config_keys.should =~ ["test_key", "test_oauth"]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,72 @@
|
|
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
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
describe SparkApi::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
|
+
SparkApi.api_key.should be_nil
|
11
|
+
SparkApi.api_secret.should be_nil
|
12
|
+
SparkApi.version.should match("v1")
|
13
|
+
SparkApi.endpoint.should match("api.sparkapi.com")
|
14
|
+
SparkApi.user_agent.should match(/Spark API Ruby Gem .*/)
|
15
|
+
SparkApi.api_key = "my_api_key"
|
16
|
+
SparkApi.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 = SparkApi::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
|
+
SparkApi.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.sparkapi.com"
|
43
|
+
config.user_agent = "my useragent"
|
44
|
+
end
|
45
|
+
|
46
|
+
SparkApi.api_key.should match("my_key")
|
47
|
+
SparkApi.api_secret.should match("my_secret")
|
48
|
+
SparkApi.api_user.should match("1234")
|
49
|
+
SparkApi.version.should match("veleventy")
|
50
|
+
SparkApi.endpoint.should match("test.api.sparkapi.com")
|
51
|
+
SparkApi.user_agent.should match("my useragent")
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should reset" do
|
56
|
+
SparkApi.configure do |config|
|
57
|
+
config.api_key = "my_key"
|
58
|
+
config.api_secret = "my_secret"
|
59
|
+
config.version = "veleventy"
|
60
|
+
config.endpoint = "test.api.sparkapi.com"
|
61
|
+
config.user_agent = "my useragent"
|
62
|
+
end
|
63
|
+
|
64
|
+
SparkApi.api_key.should match("my_key")
|
65
|
+
SparkApi.reset
|
66
|
+
SparkApi.api_key.should == SparkApi::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, "#{SparkApi.endpoint}/#{SparkApi.version}/connections").
|
75
|
+
with(:query => {
|
76
|
+
:ApiSig => "951e5ba0496b0758356d3cc7676f8b21",
|
77
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573"
|
78
|
+
}).
|
79
|
+
to_return(:body => '{"D":{"Success": true,"Results": [{"SSL":false}]}}')
|
80
|
+
|
81
|
+
SparkApi.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.sparkapi.com/#{SparkApi.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 = SparkApi::Client.new(:endpoint => "https://api.sparkapi.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, "#{SparkApi.endpoint}/#{SparkApi.version}/headers").
|
100
|
+
with(:query => {
|
101
|
+
:ApiSig => "6f0cfef263e0bfe7a9ae1f60063a8ad9",
|
102
|
+
:AuthToken => "c401736bf3d3f754f07c04e460e09573"
|
103
|
+
}).
|
104
|
+
to_return(:body => '{"D":{"Success": true,"Results": []}}')
|
105
|
+
SparkApi.reset
|
106
|
+
SparkApi.configure do |config|
|
107
|
+
config.user_agent = "my useragent"
|
108
|
+
end
|
109
|
+
SparkApi.client.get '/headers'
|
110
|
+
WebMock.should have_requested(:get, "#{SparkApi.endpoint}/#{SparkApi.version}/headers?ApiSig=6f0cfef263e0bfe7a9ae1f60063a8ad9&AuthToken=c401736bf3d3f754f07c04e460e09573").
|
111
|
+
with(:headers => {
|
112
|
+
'User-Agent' => SparkApi::Configuration::DEFAULT_USER_AGENT,
|
113
|
+
SparkApi::Configuration::X_SPARK_API_USER_AGENT => "my useragent",
|
114
|
+
'Accept'=>'application/json',
|
115
|
+
'Content-Type'=>'application/json'
|
116
|
+
})
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,122 @@
|
|
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
|
+
|