spark_api 1.2.1 → 1.3.0

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 (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
@@ -0,0 +1,44 @@
1
+ module SparkApi
2
+ module Models
3
+ class VowAccount < Base
4
+ extend Finders
5
+ include Concerns::Savable,
6
+ Concerns::Destroyable
7
+
8
+ self.element_name = "portal"
9
+
10
+ def initialize(attributes={})
11
+ super(attributes)
12
+ end
13
+
14
+ def enabled?
15
+ (@attributes['Settings'].class == Hash) && @attributes['Settings']['Enabled'] == 'true'
16
+ end
17
+
18
+ def enable
19
+ change_setting :Enabled, 'true'
20
+ save
21
+ end
22
+
23
+ def disable
24
+ change_setting :Enabled, 'false'
25
+ save
26
+ end
27
+
28
+ def change_password(new_password)
29
+ attribute_will_change! 'Password'
30
+ @attributes['Password'] = new_password
31
+ save
32
+ end
33
+
34
+ def change_setting(key, val)
35
+ attribute_will_change! "Settings"
36
+ @attributes['Settings'] = {} if @attributes['Settings'].nil? || @attributes['Settings'] != Hash
37
+ @attributes['Settings'][key.to_s] = val
38
+ end
39
+
40
+ def post_data; attributes end
41
+
42
+ end
43
+ end
44
+ end
@@ -98,7 +98,7 @@ module SparkApi
98
98
 
99
99
  def process_request_body(body)
100
100
  if body.is_a?(Hash)
101
- body.empty? ? "{}" : {"D" => body }.to_json
101
+ body.empty? ? nil : {"D" => body }.to_json
102
102
  else
103
103
  body
104
104
  end
@@ -0,0 +1,22 @@
1
+ {
2
+ "D": {
3
+ "Results": [
4
+ {
5
+ "Id":"20121128132106172132000004",
6
+ "ResourceUri":"/v1/activities/20121128132106172132000004",
7
+ "ActivityId":null,
8
+ "CreatedTimestamp":"2012-11-28T13:21:06Z",
9
+ "ActivityResourceUri":"/v1/contacts/20121102143633121730000000/comments",
10
+ "ActivityType":"ContactComment"
11
+ },
12
+ {
13
+ "Id":"20121128132106172132000005",
14
+ "ResourceUri":"/v1/activities/20121128132106172132000005",
15
+ "ActivityId":null,
16
+ "CreatedTimestamp":"2012-11-28T13:21:06Z",
17
+ "ActivityResourceUri":"/v1/contacts/20121102143633121730000000/comments",
18
+ "ActivityType":"ContactComment"
19
+ }
20
+ ]
21
+ }
22
+ }
@@ -2,13 +2,13 @@
2
2
  "Success": true,
3
3
  "Results": [{
4
4
  "Id": 1,
5
- "ResourceUri": "some/place/123",
5
+ "ResourceUri": "/v1/some/place/20101230223226074201000000",
6
6
  "Name": "My Example",
7
7
  "Test": true
8
8
  },
9
9
  {
10
10
  "Id": 2,
11
- "ResourceUri": "some/place/123",
11
+ "ResourceUri": "/v1/some/place/20101230223226074204000000",
12
12
  "Name": "My Example2",
13
13
  "Test": false
14
14
  }]}
@@ -0,0 +1,32 @@
1
+ {
2
+ "D": {
3
+ "Results": [
4
+ {
5
+ "CreatedTimestamp":"2012-11-14T10:02:01-06:00",
6
+ "UserId":"20000426143505724628000000",
7
+ "ReferenceId":"20110105173455471471000000",
8
+ "ResourceUri":"/v1/activities/20121128132106172132000004/comments/20121128133936712557000097",
9
+ "UserUri":"/v1/accounts/20000426143505724628000000",
10
+ "ModificationTimestamp":"2012-11-14T10:02:01-06:00",
11
+ "ReferenceType":"Contact",
12
+ "Comment":"This is a comment.",
13
+ "ReferenceUri":"/v1/contacts/20110105173455471471000000",
14
+ "UserType":"Mls",
15
+ "Id":"20121128133936712557000097"
16
+ },
17
+ {
18
+ "CreatedTimestamp":"2012-11-14T10:02:01-06:00",
19
+ "UserId":"20000426143505724628000000",
20
+ "ReferenceId":"20110105173455471471000000",
21
+ "ResourceUri":"/v1/activities/20121128132106172132000004/comments/20121128133936712557000098",
22
+ "UserUri":"/v1/accounts/20000426143505724628000000",
23
+ "ModificationTimestamp":"2012-11-14T10:02:01-06:00",
24
+ "ReferenceType":"Contact",
25
+ "Comment":"This is another comment.",
26
+ "ReferenceUri":"/v1/contacts/20110105173455471471000000",
27
+ "UserType":"Mls",
28
+ "Id":"20121128133936712557000098"
29
+ }
30
+ ]
31
+ }
32
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "D": {
3
+ "Comments": [
4
+ { "Comment": "This is a comment." }
5
+ ]
6
+ }
7
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "D": {
3
+ "Results": [
4
+ {
5
+ "CreatedTimestamp":"2012-11-14T10:02:01-06:00",
6
+ "UserId":"20000426143505724628000000",
7
+ "ReferenceId":"20110105173455471471000000",
8
+ "ResourceUri":"/v1/contacts/20110105173455471471000000/comments/20121114100201798092000005",
9
+ "UserUri":"/v1/accounts/20000426143505724628000000",
10
+ "ModificationTimestamp":"2012-11-14T10:02:01-06:00",
11
+ "ReferenceType":"Contact",
12
+ "Comment":"This is a comment.",
13
+ "ReferenceUri":"/v1/contacts/20110105173455471471000000",
14
+ "UserType":"Mls",
15
+ "Id":"20121114100201798092000005"
16
+ }
17
+ ]
18
+ }
19
+ }
@@ -6,6 +6,7 @@
6
6
  "ResourceUri": "/v1/my/contact",
7
7
  "DisplayName": "BH FOO",
8
8
  "Id": "20090928182824338901000000",
9
+ "ResourceUri":"/v1/contacts/20090928182824338901000000",
9
10
  "Tags": [
10
11
  "IDX Lead"
11
12
  ],
@@ -0,0 +1,5 @@
1
+ {
2
+ "D": {
3
+ "LoginName": "Johnny Newman"
4
+ }
5
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [{
5
+ "ResourceUri": "/v1/contacts/20090928182824338901000000/portal",
6
+ "Id": "20060412165917817933000000",
7
+ "OwnerId": "20090410349683017933000000",
8
+ "LoginName": "dave",
9
+ "LastLogin": "2012-03-07T20:09:37Z",
10
+ "Locale": {
11
+ "Language": "en"
12
+ }
13
+ }]
14
+ }
15
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "D":{
3
+ "LoginName":"Johnny Everyman",
4
+ "Password":"MyPassw0rd",
5
+ "Settings":{
6
+ "Enabled":"true"
7
+ },
8
+ "Locale":{
9
+ "Language":"en"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "ResourceUri":"/v1/contacts/20090928182824338901000000/portal"
7
+ }
8
+ ]
9
+ }
10
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "A": [
7
+ {
8
+ "Contract Information": [
9
+ {
10
+ "Field": "23Patios",
11
+ "Label": "Book Section",
12
+ "Domain": "CustomFields",
13
+ "Detail": true
14
+ }
15
+ ]
16
+ }
17
+ ],
18
+ "B": [ ]
19
+ }
20
+ ]
21
+ }
22
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "Contract Information": [
7
+ {
8
+ "Field": "23Patios",
9
+ "Label": "Book Section",
10
+ "Domain": "CustomFields",
11
+ "Detail": true
12
+ },
13
+ {
14
+ "Field": "ListPrice",
15
+ "Label": "List Price",
16
+ "Domain": "StandardFields",
17
+ "Detail": false
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "General Property Description": [
23
+ {
24
+ "Field": "24Patios",
25
+ "Label": "Street Number",
26
+ "Domain": "CustomFields",
27
+ "Detail": true
28
+ },
29
+ {
30
+ "Field": "MlsStatus",
31
+ "Label": "Total Square Feet",
32
+ "Domain": "StandardFields",
33
+ "Detail": false
34
+ }
35
+ ]
36
+ }
37
+ ]
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "D": {
3
+ "Enabled": false
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "D": {
3
+ "Enabled": true
4
+ }
5
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [{
5
+ "ResourceUri": "/v1/portal/20100912153422758914000000",
6
+ "Id": "20100912153422758914000000",
7
+ "OwnerId": "20110000000000000000000001",
8
+ "ModificationTimestamp": "2011-11-18T16:35:43",
9
+ "Name": "greatportal",
10
+ "DisplayName": "GreatPortal",
11
+ "Enabled": true,
12
+ "RequiredFields": ["Address", "Phone"]
13
+ }]
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": []
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "D": {
3
+ "DisplayName": "GreatPortal",
4
+ "Enabled": true,
5
+ "RequiredFields": ["Address", "Phone"]
6
+ }
7
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "D": {
3
+ "Success": true,
4
+ "Results": [
5
+ {
6
+ "ResourceUri":"/v1/portal/20100912153422758914000000"
7
+ }
8
+ ]
9
+ }
10
+ }
@@ -5,7 +5,10 @@
5
5
  {
6
6
  "ResourceUri": "/v1/savedsearches/20100815220615294367000000",
7
7
  "Id": "20100815220615294367000000",
8
- "Name": "Search name here"
8
+ "Name": "Search name here",
9
+ "ContactIds": [
10
+ "20100815220615294367000000"
11
+ ]
9
12
  },
10
13
  {
11
14
  "ResourceUri": "/v1/savedsearches/20100615220615292711000000",
@@ -1,20 +1,16 @@
1
1
  require "rubygems"
2
- require "json"
3
- require 'multi_json'
2
+
4
3
  require "rspec"
5
4
  require 'rspec/autorun'
6
5
  require 'webmock/rspec'
6
+ require "json"
7
+ require 'multi_json'
7
8
 
8
- begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
9
9
  path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
10
10
  $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
11
11
  require path + '/spark_api'
12
12
 
13
13
  require 'spark_api'
14
- require File.expand_path('../mock_helper', __FILE__)
15
- require File.expand_path('../json_helper', __FILE__)
16
- require File.expand_path('../json_hash_test_support', __FILE__)
17
-
18
14
 
19
15
  FileUtils.mkdir 'log' unless File.exists? 'log'
20
16
 
@@ -38,6 +34,10 @@ def reset_config
38
34
  SparkApi.configure { |c| c.api_user = "foobar" }
39
35
  end
40
36
 
37
+ # Requires supporting ruby files with custom matchers and macros, etc,
38
+ # # in spec/support/ and its subdirectories.
39
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
40
+
41
41
  RSpec.configure do |config|
42
42
  config.treat_symbols_as_metadata_keys_with_true_values = true
43
43
  config.alias_example_to :on_get_it, :method => 'GET'
@@ -46,3 +46,7 @@ RSpec.configure do |config|
46
46
  config.alias_example_to :on_delete_it, :method => 'DELETE'
47
47
  config.before(:all) { reset_config }
48
48
  end
49
+
50
+ def jruby?
51
+ RUBY_PLATFORM == "java"
52
+ end
@@ -1,5 +1,5 @@
1
- require './spec/spec_helper'
2
- require './spec/oauth2_helper'
1
+ require 'spec_helper'
2
+ require 'support/oauth2_helper'
3
3
 
4
4
  describe SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware do
5
5
  subject { SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware.new("test") }
@@ -1,5 +1,4 @@
1
- require './spec/spec_helper'
2
- require './spec/oauth2_helper'
1
+ require 'spec_helper'
3
2
 
4
3
  describe SparkApi::Authentication::OAuth2Impl::GrantTypeBase do
5
4
  subject { SparkApi::Authentication::OAuth2Impl::GrantTypeBase }
@@ -1,5 +1,4 @@
1
- require './spec/spec_helper'
2
- require './spec/oauth2_helper'
1
+ require 'spec_helper'
3
2
 
4
3
  describe SparkApi::Authentication::OAuth2 do
5
4
  before(:all) { SparkApi.reset } # dump api user stuff from other tests
@@ -23,7 +22,7 @@ describe SparkApi::Authentication::OAuth2 do
23
22
  ).
24
23
  to_return(:body => fixture("oauth2/access.json"), :status=>200)
25
24
  subject.authenticate.access_token.should eq("04u7h-4cc355-70k3n")
26
- subject.authenticate.expires_in.should eq(7200)
25
+ subject.authenticate.expires_in.should eq(57600)
27
26
  end
28
27
 
29
28
  it "should raise an error when api credentials are invalid" do
@@ -246,7 +245,7 @@ describe SparkApi::Authentication::BaseOAuth2Provider do
246
245
  describe TestOAuth2Provider do
247
246
  subject { TestOAuth2Provider.new }
248
247
  it "should be able to override the session timeout" do
249
- subject.session_timeout.should eq(7200)
248
+ subject.session_timeout.should eq(57600)
250
249
  end
251
250
  end
252
251
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Activity do
4
+
5
+ before :each do
6
+ stub_auth_request
7
+ end
8
+
9
+ context '/activities' do
10
+ it "gets a current user's activities" do
11
+ s = stub_api_get("/activities", "activities/get.json")
12
+ activities = Activity.get
13
+ activities.should be_an(Array)
14
+ activities.size.should eq(2)
15
+ s.should have_been_requested
16
+ end
17
+ end
18
+
19
+ context '/activities/<id>' do
20
+ let(:id) { "20121128132106172132000004" }
21
+ it "gets an individual activity" do
22
+ s = stub_api_get("/activities/#{id}", "activities/get.json")
23
+ activity = Activity.find(id)
24
+ activity.should be_an(Activity)
25
+ s.should have_been_requested
26
+ end
27
+ end
28
+
29
+ end