spark_api 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/History.txt +12 -0
  2. data/README.md +7 -0
  3. data/Rakefile +1 -0
  4. data/VERSION +1 -1
  5. data/lib/spark_api/authentication.rb +0 -3
  6. data/lib/spark_api/authentication/oauth2.rb +1 -1
  7. data/lib/spark_api/configuration.rb +6 -1
  8. data/lib/spark_api/models.rb +6 -2
  9. data/lib/spark_api/models/activity.rb +10 -0
  10. data/lib/spark_api/models/base.rb +25 -5
  11. data/lib/spark_api/models/comment.rb +9 -0
  12. data/lib/spark_api/models/concerns/destroyable.rb +1 -1
  13. data/lib/spark_api/models/concerns/savable.rb +3 -6
  14. data/lib/spark_api/models/contact.rb +38 -1
  15. data/lib/spark_api/models/dirty.rb +1 -1
  16. data/lib/spark_api/models/fields.rb +12 -0
  17. data/lib/spark_api/models/listing_cart.rb +6 -34
  18. data/lib/spark_api/models/portal.rb +37 -0
  19. data/lib/spark_api/models/saved_search.rb +36 -0
  20. data/lib/spark_api/models/vow_account.rb +44 -0
  21. data/lib/spark_api/request.rb +1 -1
  22. data/spec/fixtures/activities/get.json +22 -0
  23. data/spec/fixtures/base.json +2 -2
  24. data/spec/fixtures/comments/get.json +32 -0
  25. data/spec/fixtures/comments/new.json +7 -0
  26. data/spec/fixtures/comments/post.json +19 -0
  27. data/spec/fixtures/contacts/my.json +1 -0
  28. data/spec/fixtures/contacts/vow_accounts/edit.json +5 -0
  29. data/spec/fixtures/contacts/vow_accounts/get.json +15 -0
  30. data/spec/fixtures/contacts/vow_accounts/new.json +12 -0
  31. data/spec/fixtures/contacts/vow_accounts/post.json +10 -0
  32. data/spec/fixtures/fields/order.json +22 -0
  33. data/spec/fixtures/fields/order_a.json +39 -0
  34. data/spec/fixtures/portal/disable.json +5 -0
  35. data/spec/fixtures/portal/enable.json +5 -0
  36. data/spec/fixtures/portal/my.json +15 -0
  37. data/spec/fixtures/portal/my_non_existant.json +6 -0
  38. data/spec/fixtures/portal/new.json +7 -0
  39. data/spec/fixtures/portal/post.json +10 -0
  40. data/spec/fixtures/saved_searches/get.json +4 -1
  41. data/spec/spec_helper.rb +11 -7
  42. data/spec/unit/spark_api/authentication/oauth2_impl/faraday_middleware_spec.rb +2 -2
  43. data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +1 -2
  44. data/spec/unit/spark_api/authentication/oauth2_spec.rb +3 -4
  45. data/spec/unit/spark_api/models/activity_spec.rb +29 -0
  46. data/spec/unit/spark_api/models/base_spec.rb +23 -0
  47. data/spec/unit/spark_api/models/concerns/destroyable_spec.rb +1 -1
  48. data/spec/unit/spark_api/models/concerns/savable_spec.rb +8 -4
  49. data/spec/unit/spark_api/models/contact_spec.rb +144 -21
  50. data/spec/unit/spark_api/models/fields_spec.rb +56 -0
  51. data/spec/unit/spark_api/models/listing_cart_spec.rb +1 -1
  52. data/spec/unit/spark_api/models/portal_spec.rb +50 -0
  53. data/spec/unit/spark_api/models/saved_search_spec.rb +60 -0
  54. data/spec/unit/spark_api/models/shared_listing_spec.rb +1 -1
  55. data/spec/unit/spark_api/models/vow_account_spec.rb +64 -0
  56. data/spec/unit/spark_api/request_spec.rb +1 -1
  57. data/spec/unit/spark_api_spec.rb +1 -1
  58. metadata +362 -360
  59. data/lib/spark_api/models/subscription.rb +0 -52
  60. data/spec/fixtures/subscriptions/get.json +0 -19
  61. data/spec/fixtures/subscriptions/new.json +0 -13
  62. data/spec/fixtures/subscriptions/post.json +0 -10
  63. data/spec/fixtures/subscriptions/put.json +0 -12
  64. data/spec/fixtures/subscriptions/subscribe.json +0 -5
  65. data/spec/fixtures/subscriptions/update.json +0 -6
  66. data/spec/json_hash_test_support.rb +0 -251
  67. data/spec/json_helper.rb +0 -76
  68. data/spec/mock_helper.rb +0 -132
  69. data/spec/oauth2_helper.rb +0 -70
  70. data/spec/unit/spark_api/models/subscription_spec.rb +0 -106
@@ -1,132 +0,0 @@
1
- RSpec.configure do |config|
2
- config.include WebMock::API
3
- end
4
-
5
- $test_client = SparkApi::Client.new({:api_key=>"", :api_secret=>""})
6
- def stub_api_get(service_path, stub_fixture="success.json", opts={})
7
- params = {:ApiUser => "foobar", :AuthToken => "c401736bf3d3f754f07c04e460e09573"}.merge(opts)
8
- sig = $test_client.authenticator.sign_token("/#{SparkApi.version}#{service_path}", params)
9
- s=stub_request(:get, "#{SparkApi.endpoint}/#{SparkApi.version}#{service_path}").
10
- with(:query => {
11
- :ApiSig => sig
12
- }.merge(params))
13
- if(block_given?)
14
- yield s
15
- else
16
- s.to_return(:body => fixture(stub_fixture))
17
- end
18
- log_stub(s)
19
- end
20
- def stub_api_delete(service_path, stub_fixture="success.json", opts={})
21
- params = {:ApiUser => "foobar", :AuthToken => "c401736bf3d3f754f07c04e460e09573"}.merge(opts)
22
- sig = $test_client.authenticator.sign_token("/#{SparkApi.version}#{service_path}", params)
23
- s=stub_request(:delete, "#{SparkApi.endpoint}/#{SparkApi.version}#{service_path}").
24
- with(:query => {
25
- :ApiSig => sig
26
- }.merge(params))
27
- if(block_given?)
28
- yield s
29
- else
30
- s.to_return(:body => fixture(stub_fixture))
31
- end
32
- log_stub(s)
33
- end
34
- def stub_api_post(service_path, body, stub_fixture="success.json", opts={})
35
- if body.is_a?(Hash)
36
- body = { :D => body } unless body.empty?
37
- elsif !body.nil?
38
- body = MultiJson.load(fixture(body).read)
39
- end
40
- body_str = body.nil? ? body : MultiJson.dump(body)
41
- params = {:ApiUser => "foobar", :AuthToken => "c401736bf3d3f754f07c04e460e09573"}.merge(opts)
42
- sig = $test_client.authenticator.sign_token("/#{SparkApi.version}#{service_path}", params, body_str)
43
- s=stub_request(:post, "#{SparkApi.endpoint}/#{SparkApi.version}#{service_path}").
44
- with(:query => {
45
- :ApiSig => sig
46
- }.merge(params),
47
- :body => body
48
- )
49
- if(block_given?)
50
- yield s
51
- else
52
- s.to_return(:body => fixture(stub_fixture))
53
- end
54
- log_stub(s)
55
- end
56
- def stub_api_put(service_path, body, stub_fixture="success.json", opts={})
57
- if body.is_a? Hash
58
- body = { :D => body }
59
- elsif !body.nil?
60
- body = MultiJson.load(fixture(body).read)
61
- end
62
- body_str = body.nil? ? body : MultiJson.dump(body)
63
- params = {:ApiUser => "foobar", :AuthToken => "c401736bf3d3f754f07c04e460e09573"}.merge(opts)
64
- sig = $test_client.authenticator.sign_token("/#{SparkApi.version}#{service_path}", params, body_str)
65
- s=stub_request(:put, "#{SparkApi.endpoint}/#{SparkApi.version}#{service_path}").
66
- with(:query => {
67
- :ApiSig => sig
68
- }.merge(params),
69
- :body => body
70
- )
71
- if(block_given?)
72
- yield s
73
- else
74
- s.to_return(:body => fixture(stub_fixture))
75
- end
76
- log_stub(s)
77
- end
78
-
79
- def log_stub(s)
80
- SparkApi.logger.debug("Stubbed Request: #{s.inspect} \n\n")
81
- end
82
-
83
- def mock_session()
84
- SparkApi::Authentication::Session.new("AuthToken" => "1234", "Expires" => (Time.now + 3600).to_s, "Roles" => "['idx']")
85
- end
86
-
87
- def mock_oauth_session()
88
- SparkApi::Authentication::OAuthSession.new("access_token" => "1234", "expires_in" => 3600, "scope" => nil, "refresh_token"=> "1000refresh")
89
- end
90
-
91
- class MockClient < SparkApi::Client
92
- attr_accessor :connection
93
- def connection(ssl = false)
94
- @connection
95
- end
96
- end
97
-
98
- class MockApiAuthenticator < SparkApi::Authentication::ApiAuth
99
- # Sign a request
100
- def sign(sig)
101
- "SignedToken"
102
- end
103
- end
104
-
105
- def mock_client(stubs)
106
- c = MockClient.new
107
- c.session = mock_session()
108
- c.connection = test_connection(stubs)
109
- c
110
- end
111
-
112
- def mock_expired_session()
113
- SparkApi::Authentication::Session.new("AuthToken" => "1234", "Expires" => (Time.now - 60).to_s, "Roles" => "['idx']")
114
- end
115
-
116
- def test_connection(stubs)
117
- Faraday.new(nil, {:headers => SparkApi::Client.new.headers}) do |conn|
118
- conn.response :spark_api
119
- conn.adapter :test, stubs
120
- end
121
- end
122
-
123
- def stub_auth_request()
124
- stub_request(:post, "#{SparkApi.endpoint}/#{SparkApi.version}/session").
125
- with(:query => {:ApiKey => "", :ApiSig => "806737984ab19be2fd08ba36030549ac"}).
126
- to_return(:body => fixture("session.json"))
127
- end
128
-
129
- def fixture(file)
130
- File.new(File.expand_path("../fixtures", __FILE__) + '/' + file)
131
- end
132
-
@@ -1,70 +0,0 @@
1
- # Lightweight example of an oauth2 provider used by the ruby client.
2
- class TestOAuth2Provider < SparkApi::Authentication::BaseOAuth2Provider
3
-
4
- def initialize
5
- @authorization_uri = "https://test.fbsdata.com/r/oauth2"
6
- @access_uri = "https://api.test.fbsdata.com/v1/oauth2/grant"
7
- @redirect_uri = "https://exampleapp.fbsdata.com/oauth-callback"
8
- @client_id="example-id"
9
- @client_secret="example-password"
10
- @sparkbar_uri = "https://test.sparkplatform.com/appbar/authorize"
11
- @session_cache = {}
12
- end
13
-
14
- def redirect(url)
15
- # User redirected to url, signs in, and gets code sent to callback
16
- self.code="my_code"
17
- end
18
-
19
- def load_session()
20
- @session_cache["test_user_session"]
21
- end
22
-
23
- def save_session(session)
24
- @session_cache["test_user_session"] = session
25
- nil
26
- end
27
-
28
- def session_timeout; 7200; end
29
-
30
- end
31
-
32
-
33
- class TestCLIOAuth2Provider < SparkApi::Authentication::BaseOAuth2Provider
34
- def initialize
35
- @authorization_uri = "https://test.fbsdata.com/r/oauth2"
36
- @access_uri = "https://api.test.fbsdata.com/v1/oauth2/grant"
37
- @client_id="example-id"
38
- @client_secret="example-secret"
39
- @username="example-user"
40
- @password="example-password"
41
- @session_cache = {}
42
- end
43
-
44
- def grant_type
45
- :password
46
- end
47
-
48
- def redirect(url)
49
- raise "Unsupported in oauth grant_type=password mode"
50
- end
51
-
52
- def load_session()
53
- @session_cache["test_user_session"]
54
- end
55
- def save_session(session)
56
- @session_cache["test_user_session"] = session
57
- nil
58
- end
59
- def session_timeout; 60; end
60
-
61
- end
62
-
63
-
64
- class InvalidAuth2Provider < SparkApi::Authentication::BaseOAuth2Provider
65
-
66
- def grant_type
67
- :not_a_real_type
68
- end
69
-
70
- end
@@ -1,106 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Subscription do
4
-
5
- it "responds to crud methods" do
6
- Subscription.should respond_to(:get)
7
- Subscription.new.should respond_to(:save)
8
- Subscription.new.should respond_to(:delete)
9
- end
10
-
11
- before :each do
12
- stub_auth_request
13
- end
14
-
15
- let(:id){ "20101230223226074204000000" }
16
-
17
- context "/subscriptions", :support do
18
-
19
- on_get_it "should get sum subscriptions" do
20
- stub_api_get("/subscriptions", "subscriptions/get.json")
21
- subject.class.get
22
- end
23
-
24
- on_post_it "should create a new subscription" do
25
- @subscription = Subscription.new({
26
- :Name => "A new subscription name",
27
- :SearchId => "20101230223226074204000000",
28
- :RecipientIds => [ "20101230223226074204000000" ],
29
- :Subject => "my subject",
30
- :Message => "my message"
31
- })
32
- stub_api_post("/subscriptions", 'subscriptions/new.json', 'subscriptions/post.json')
33
- @subscription.save.should be(true)
34
- @subscription.persisted?.should eq(true)
35
- end
36
-
37
- it "should subscribe a contact by id" do
38
- stub_api_get("/subscriptions/#{id}", "subscriptions/get.json")
39
- stub_api_put("/subscriptions/#{id}/subscribers/20101230223226074306000000", nil, 'subscriptions/subscribe.json')
40
- resource = subject.class.find(id)
41
- resource.subscribe("20101230223226074306000000")
42
- resource.RecipientIds.size.should eq(2)
43
- resource.RecipientIds.any? { |c| c == "20101230223226074306000000" }.should eq(true)
44
- end
45
-
46
- it "should unsubscribe a contact by id" do
47
- stub_api_get("/subscriptions/#{id}", "subscriptions/get.json")
48
- stub_api_delete("/subscriptions/#{id}/subscribers/20101230223226074307000000", 'generic_delete.json')
49
- resource = subject.class.find(id)
50
- resource.unsubscribe("20101230223226074307000000")
51
- resource.RecipientIds.size.should eq(0)
52
- end
53
-
54
- it "should subscribe a contact by Contact object" do
55
- stub_api_get("/subscriptions/#{id}", "subscriptions/get.json")
56
- stub_api_put("/subscriptions/#{id}/subscribers/20101230223226074306000000", nil, 'subscriptions/subscribe.json')
57
- resource = subject.class.find(id)
58
- resource.subscribe(Contact.new({ :Id => "20101230223226074306000000" }))
59
- resource.RecipientIds.size.should eq(2)
60
- resource.RecipientIds.any? { |c| c == "20101230223226074306000000" }.should eq(true)
61
- end
62
-
63
- it "should unsubscribe a contact by Contact object" do
64
- stub_api_get("/subscriptions/#{id}", "subscriptions/get.json")
65
- stub_api_delete("/subscriptions/#{id}/subscribers/20101230223226074307000000", 'generic_delete.json')
66
- resource = subject.class.find(id)
67
- resource.unsubscribe(Contact.new({ :Id => "20101230223226074307000000" }))
68
- resource.RecipientIds.size.should eq(0)
69
- end
70
-
71
- it "should initialize RecipientIds as an array if nil" do
72
- stub_api_get("/subscriptions/#{id}", "subscriptions/get.json")
73
- stub_api_put("/subscriptions/#{id}/subscribers/20101230223226074306000000", nil, 'subscriptions/subscribe.json')
74
- resource = subject.class.find(id)
75
- resource.RecipientIds = nil
76
- resource.subscribe(Contact.new({ :Id => "20101230223226074306000000" }))
77
- resource.RecipientIds.size.should eq(1)
78
- end
79
-
80
- end
81
-
82
- context "/subscriptions/:id", :support do
83
-
84
- on_get_it "should get a subscription" do
85
- stub_api_get("/subscriptions/#{id}", "subscriptions/get.json")
86
- subject.class.find(id)
87
- end
88
-
89
- on_put_it "should update a subscription" do
90
- stub_api_get("/subscriptions/#{id}", 'subscriptions/get.json')
91
- stub_api_put("/subscriptions/#{id}", 'subscriptions/update.json', 'subscriptions/post.json')
92
- resource = subject.class.find(id)
93
- resource.Name = "A new subscription name"
94
- resource.save.should be(true)
95
- end
96
-
97
- on_delete_it "should delete a subscription" do
98
- stub_api_get("/subscriptions/#{id}", 'subscriptions/get.json')
99
- stub_api_delete("/subscriptions/#{id}", 'generic_delete.json')
100
- resource = subject.class.find(id)
101
- resource.delete
102
- end
103
-
104
- end
105
-
106
- end