spark_api 1.1.1 → 1.1.2
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.
- data/VERSION +1 -1
- data/lib/spark_api/client.rb +1 -2
- data/lib/spark_api/connection.rb +0 -1
- data/lib/spark_api/models/finders.rb +4 -0
- data/lib/spark_api/models/subresource.rb +33 -13
- data/spec/fixtures/finders.json +14 -0
- data/spec/fixtures/listings/open_houses.json +3 -3
- data/spec/mock_helper.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/spark_api/models/finders_spec.rb +32 -0
- data/spec/unit/spark_api/models/open_house_spec.rb +2 -16
- data/spec/unit/spark_api/models/subresource_spec.rb +74 -0
- data/spec/unit/spark_api/models/tour_of_home_spec.rb +2 -16
- data/spec/unit/spark_api/multi_client_spec.rb +4 -0
- data/spec/unit/spark_api/paginate_spec.rb +1 -1
- metadata +10 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/lib/spark_api/client.rb
CHANGED
@@ -16,8 +16,7 @@ module SparkApi
|
|
16
16
|
|
17
17
|
# Constructor bootstraps the client with configuration and authorization class.
|
18
18
|
# options - see Configuration::VALID_OPTION_KEYS
|
19
|
-
|
20
|
-
def initialize(options={}, auth_klass=ApiAuth)
|
19
|
+
def initialize(options={})
|
21
20
|
options = SparkApi.options.merge(options)
|
22
21
|
Configuration::VALID_OPTION_KEYS.each do |key|
|
23
22
|
send("#{key}=", options[key])
|
data/lib/spark_api/connection.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module SparkApi
|
2
2
|
module Models
|
3
|
-
module Subresource
|
4
|
-
|
3
|
+
module Subresource
|
4
|
+
|
5
5
|
def build_subclass
|
6
6
|
Class.new(self)
|
7
7
|
end
|
@@ -9,31 +9,51 @@ module SparkApi
|
|
9
9
|
def find_by_listing_key(key, arguments={})
|
10
10
|
collect(connection.get("/listings/#{key}#{self.path}", arguments))
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def find_by_id(id, parent_id, arguments={})
|
14
14
|
collect(connection.get("/listings/#{parent_id}#{self.path}/#{id}", arguments)).first
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def parse_date_start_and_end_times(attributes)
|
18
18
|
# Transform the date strings
|
19
19
|
unless attributes['Date'].nil?
|
20
20
|
date = Date.strptime attributes['Date'], '%m/%d/%Y'
|
21
21
|
['StartTime','EndTime'].each do |time|
|
22
22
|
next if attributes[time].nil?
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
formatted_date = "#{attributes['Date']}T#{attributes[time]}"
|
24
|
+
datetime = nil
|
25
|
+
|
26
|
+
begin
|
27
|
+
datetime = DateTime.strptime(formatted_date, '%m/%d/%YT%l:%M %P')
|
28
|
+
rescue => ex
|
29
|
+
; # Do nothing; doesn't matter
|
30
|
+
end
|
31
|
+
|
32
|
+
unless datetime
|
33
|
+
other_formats = ['%m/%d/%YT%H:%M%z', '%m/%d/%YT%H:%M:%S%z']
|
34
|
+
other_formats.each_with_index do |format, i|
|
35
|
+
begin
|
36
|
+
datetime = DateTime.strptime(formatted_date, format)
|
37
|
+
datetime = datetime.new_offset DateTime.now.offset
|
38
|
+
break
|
39
|
+
rescue => ex
|
40
|
+
next
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# if we still don't have a valid time, raise an error
|
46
|
+
unless datetime
|
47
|
+
raise ArgumentError.new('invalid date')
|
26
48
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
attributes[time] = Time.local(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min,
|
31
|
-
datetime.sec)
|
49
|
+
|
50
|
+
attributes[time] = Time.local(datetime.year, datetime.month, datetime.day,
|
51
|
+
datetime.hour, datetime.min, datetime.sec)
|
32
52
|
end
|
33
53
|
attributes['Date'] = date
|
34
54
|
end
|
35
55
|
end
|
36
|
-
|
56
|
+
|
37
57
|
end
|
38
58
|
end
|
39
59
|
end
|
@@ -6,8 +6,8 @@
|
|
6
6
|
"ResourceUri": "/v1/listings/20060412165917817933000000/openhouses/20101127153422574618000000",
|
7
7
|
"Id": "20101127153422574618000000",
|
8
8
|
"Date": "10/01/2010",
|
9
|
-
"StartTime": "
|
10
|
-
"EndTime": "12:00
|
9
|
+
"StartTime": "9:00 am",
|
10
|
+
"EndTime": "12:00 pm"
|
11
11
|
},
|
12
12
|
{
|
13
13
|
"ResourceUri": "/v1/listings/20060412165917817933000000/openhouses/20101127153422174618000000",
|
@@ -18,4 +18,4 @@
|
|
18
18
|
}
|
19
19
|
]
|
20
20
|
}
|
21
|
-
}
|
21
|
+
}
|
data/spec/mock_helper.rb
CHANGED
@@ -113,7 +113,7 @@ def test_connection(stubs)
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def stub_auth_request()
|
116
|
-
stub_request(:post, "
|
116
|
+
stub_request(:post, "#{SparkApi.endpoint}/#{SparkApi.version}/session").
|
117
117
|
with(:query => {:ApiKey => "", :ApiSig => "806737984ab19be2fd08ba36030549ac"}).
|
118
118
|
to_return(:body => fixture("session.json"))
|
119
119
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
class MyResource < Base
|
4
|
+
extend Finders
|
5
|
+
self.element_name = "my_resource"
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Finders, "Finders model" do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
stub_auth_request
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should get all results" do
|
15
|
+
stub_api_get("/my_resource", 'finders.json')
|
16
|
+
resources = MyResource.all
|
17
|
+
resources.size.should eq(2)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get first result" do
|
21
|
+
stub_api_get("/my_resource", 'finders.json')
|
22
|
+
resource = MyResource.first
|
23
|
+
resource.Id.should eq(1)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get last result" do
|
27
|
+
stub_api_get("/my_resource", 'finders.json')
|
28
|
+
resource = MyResource.last
|
29
|
+
resource.Id.should eq(2)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -8,8 +8,8 @@ describe OpenHouse do
|
|
8
8
|
'ResourceUri'=>"/v1/listings/20060412165917817933000000/openhouses/20101127153422574618000000",
|
9
9
|
'Id'=>"20060412165917817933000000",
|
10
10
|
'Date'=>"10/01/2010",
|
11
|
-
'StartTime'=>"
|
12
|
-
'EndTime'=>"12:00
|
11
|
+
'StartTime'=>"9:00 am",
|
12
|
+
'EndTime'=>"12:00 pm"
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
@@ -17,20 +17,6 @@ describe OpenHouse do
|
|
17
17
|
subject.class.should respond_to(:find_by_listing_key)
|
18
18
|
end
|
19
19
|
|
20
|
-
it "should return date and times" do
|
21
|
-
start_time = DateTime.new(2010,10,1,9,0,0, "-0700")
|
22
|
-
end_time = DateTime.new(2010,10,1,12,0,0, "-0700")
|
23
|
-
subject.Date.should eq(Date.new(2010,10,1))
|
24
|
-
# TRYING TO MAKE THIS BACKWARDS COMPATIBLE AND NOT HAPPY ABOUT IT
|
25
|
-
if RUBY_VERSION < '1.9'
|
26
|
-
subject.StartTime.should eq(Time.parse(start_time.to_s))
|
27
|
-
subject.EndTime.should eq(Time.parse(end_time.to_s))
|
28
|
-
else
|
29
|
-
subject.StartTime.should eq(start_time.to_time)
|
30
|
-
subject.EndTime.should eq(end_time.to_time)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
20
|
context "/listings/<listing_id>/openhouses", :support do
|
35
21
|
on_get_it "should get open house for a listing" do
|
36
22
|
stub_auth_request
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
describe Subresource do
|
6
|
+
let(:dummy_class) do
|
7
|
+
Class.new do
|
8
|
+
extend(Subresource)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should handle times without tz offset" do
|
13
|
+
times = {'Date' => '10/01/2012', 'StartTime' => '9:00 am', 'EndTime' => '12:00 pm'}
|
14
|
+
start_time = Time.local(2012,10,1,9,0,0)
|
15
|
+
end_time = Time.local(2012,10,1,12,0,0)
|
16
|
+
date = Date.new(2012,10,1)
|
17
|
+
|
18
|
+
dummy_class.parse_date_start_and_end_times(times)
|
19
|
+
|
20
|
+
times['Date'].should eq(date)
|
21
|
+
|
22
|
+
if RUBY_VERSION < '1.9'
|
23
|
+
times['StartTime'].should eq(Time.parse(start_time.to_s))
|
24
|
+
times['EndTime'].should eq(Time.parse(end_time.to_s))
|
25
|
+
else
|
26
|
+
times['StartTime'].should eq(start_time.to_time)
|
27
|
+
times['EndTime'].should eq(end_time.to_time)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should handle times with tz offset" do
|
32
|
+
times = {'Date' => '10/01/2012', 'StartTime' => '09:00-0700', 'EndTime' => '12:00-0700'}
|
33
|
+
start_time = DateTime.new(2012,10,1,9,0,0,'-0700')
|
34
|
+
end_time = DateTime.new(2012,10,1,12,0,0,'-0700')
|
35
|
+
date = Date.new(2012,10,1)
|
36
|
+
|
37
|
+
dummy_class.parse_date_start_and_end_times(times)
|
38
|
+
|
39
|
+
times['Date'].should eq(date)
|
40
|
+
|
41
|
+
if RUBY_VERSION < '1.9'
|
42
|
+
times['StartTime'].should eq(Time.parse(start_time.to_s))
|
43
|
+
times['EndTime'].should eq(Time.parse(end_time.to_s))
|
44
|
+
else
|
45
|
+
times['StartTime'].should eq(start_time.to_time)
|
46
|
+
times['EndTime'].should eq(end_time.to_time)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should handle times with tz offset and seconds" do
|
51
|
+
times = {'Date' => '10/01/2012', 'StartTime' => '09:12:34-0700', 'EndTime' => '12:43:21-0700'}
|
52
|
+
start_time = DateTime.new(2012,10,1,9,12,34,'-0700')
|
53
|
+
end_time = DateTime.new(2012,10,1,12,43,21,'-0700')
|
54
|
+
date = Date.new(2012,10,1)
|
55
|
+
|
56
|
+
dummy_class.parse_date_start_and_end_times(times)
|
57
|
+
|
58
|
+
times['Date'].should eq(date)
|
59
|
+
|
60
|
+
if RUBY_VERSION < '1.9'
|
61
|
+
times['StartTime'].should eq(Time.parse(start_time.to_s))
|
62
|
+
times['EndTime'].should eq(Time.parse(end_time.to_s))
|
63
|
+
else
|
64
|
+
times['StartTime'].should eq(start_time.to_time)
|
65
|
+
times['EndTime'].should eq(end_time.to_time)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should raise an exception for unsupported formats" do
|
70
|
+
times = {'Date' => '10/01/2012', 'StartTime' => '_9:00_ _am_', 'EndTime' => '_12:00_ _pm_'}
|
71
|
+
|
72
|
+
expect {dummy_class.parse_date_start_and_end_times(times)}.to raise_error(ArgumentError)
|
73
|
+
end
|
74
|
+
end
|
@@ -8,8 +8,8 @@ describe TourOfHome do
|
|
8
8
|
'ResourceUri'=>"/listings/20060725224713296297000000/tourofhomes/20101127153422574618000000",
|
9
9
|
'Id'=>"20101127153422574618000000",
|
10
10
|
'Date'=>"10/01/2010",
|
11
|
-
'StartTime'=>"
|
12
|
-
'EndTime'=>"
|
11
|
+
'StartTime'=>"9:00 am",
|
12
|
+
'EndTime'=>"11:00 pm",
|
13
13
|
'Comments'=>"Wonderful home; must see!",
|
14
14
|
'AdditionalInfo'=> [{"Hosted By"=>"Joe Smith"}, {"Host Phone"=>"123-456-7890"}, {"Tour Area"=>"North-Central"}]
|
15
15
|
)
|
@@ -19,20 +19,6 @@ describe TourOfHome do
|
|
19
19
|
subject.class.should respond_to(:find_by_listing_key)
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should return tour date and times" do
|
23
|
-
start_time = DateTime.new(2010,10,1,9,0,0, "-0700")
|
24
|
-
end_time = DateTime.new(2010,10,1,23,0,0, "-0700")
|
25
|
-
subject.Date.should eq(Date.new(2010,10,1))
|
26
|
-
# TRYING TO MAKE THIS BACKWARDS COMPATIBLE AND NOT HAPPY ABOUT IT
|
27
|
-
if RUBY_VERSION < '1.9'
|
28
|
-
subject.StartTime.should eq(Time.parse(start_time.to_s))
|
29
|
-
subject.EndTime.should eq(Time.parse(end_time.to_s))
|
30
|
-
else
|
31
|
-
subject.StartTime.should eq(start_time.to_time)
|
32
|
-
subject.EndTime.should eq(end_time.to_time)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
22
|
context "/listings/<listing_id>/tourofhomes", :support do
|
37
23
|
on_get_it "should get home tours for a listing" do
|
38
24
|
stub_auth_request
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spark_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Hornseth
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-09-07 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -387,6 +387,7 @@ files:
|
|
387
387
|
- spec/fixtures/listings/virtual_tours_index.json
|
388
388
|
- spec/fixtures/listings/document_index.json
|
389
389
|
- spec/fixtures/listings/constraints.json
|
390
|
+
- spec/fixtures/finders.json
|
390
391
|
- spec/fixtures/notifications/notifications.json
|
391
392
|
- spec/fixtures/notifications/new_empty.json
|
392
393
|
- spec/fixtures/notifications/unread.json
|
@@ -428,9 +429,11 @@ files:
|
|
428
429
|
- spec/unit/spark_api/models/shared_listing_spec.rb
|
429
430
|
- spec/unit/spark_api/models/note_spec.rb
|
430
431
|
- spec/unit/spark_api/models/connect_prefs_spec.rb
|
432
|
+
- spec/unit/spark_api/models/subresource_spec.rb
|
431
433
|
- spec/unit/spark_api/models/photo_spec.rb
|
432
434
|
- spec/unit/spark_api/models/base_spec.rb
|
433
435
|
- spec/unit/spark_api/models/tour_of_home_spec.rb
|
436
|
+
- spec/unit/spark_api/models/finders_spec.rb
|
434
437
|
- spec/unit/spark_api/models/system_info_spec.rb
|
435
438
|
- spec/unit/spark_api/models/standard_fields_spec.rb
|
436
439
|
- spec/unit/spark_api/faraday_middleware_spec.rb
|
@@ -550,6 +553,7 @@ test_files:
|
|
550
553
|
- spec/fixtures/listings/virtual_tours_index.json
|
551
554
|
- spec/fixtures/listings/document_index.json
|
552
555
|
- spec/fixtures/listings/constraints.json
|
556
|
+
- spec/fixtures/finders.json
|
553
557
|
- spec/fixtures/notifications/notifications.json
|
554
558
|
- spec/fixtures/notifications/new_empty.json
|
555
559
|
- spec/fixtures/notifications/unread.json
|
@@ -591,9 +595,11 @@ test_files:
|
|
591
595
|
- spec/unit/spark_api/models/shared_listing_spec.rb
|
592
596
|
- spec/unit/spark_api/models/note_spec.rb
|
593
597
|
- spec/unit/spark_api/models/connect_prefs_spec.rb
|
598
|
+
- spec/unit/spark_api/models/subresource_spec.rb
|
594
599
|
- spec/unit/spark_api/models/photo_spec.rb
|
595
600
|
- spec/unit/spark_api/models/base_spec.rb
|
596
601
|
- spec/unit/spark_api/models/tour_of_home_spec.rb
|
602
|
+
- spec/unit/spark_api/models/finders_spec.rb
|
597
603
|
- spec/unit/spark_api/models/system_info_spec.rb
|
598
604
|
- spec/unit/spark_api/models/standard_fields_spec.rb
|
599
605
|
- spec/unit/spark_api/faraday_middleware_spec.rb
|