threetaps-client 0.5.1
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/Gemfile +17 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/lib/client/client.rb +43 -0
- data/lib/client/geocoder_client.rb +42 -0
- data/lib/client/posting_client.rb +88 -0
- data/lib/client/reference_client.rb +60 -0
- data/lib/client/search_client.rb +82 -0
- data/lib/client/status_client.rb +72 -0
- data/lib/dto/geocoder/geocoder_request.rb +16 -0
- data/lib/dto/geocoder/geocoder_response.rb +7 -0
- data/lib/dto/posting/create_response.rb +23 -0
- data/lib/dto/posting/delete_response.rb +9 -0
- data/lib/dto/posting/exists_response.rb +16 -0
- data/lib/dto/posting/update_response.rb +9 -0
- data/lib/dto/search/best_match_response.rb +20 -0
- data/lib/dto/search/count_response.rb +9 -0
- data/lib/dto/search/query_request +0 -0
- data/lib/dto/search/range_request.rb +23 -0
- data/lib/dto/search/range_response.rb +26 -0
- data/lib/dto/search/search_request.rb +79 -0
- data/lib/dto/search/search_response.rb +37 -0
- data/lib/dto/search/summary_request.rb +13 -0
- data/lib/dto/search/summary_response.rb +20 -0
- data/lib/dto/status/get_status_response.rb +43 -0
- data/lib/dto/status/status_update_request.rb +27 -0
- data/lib/models/annotations/annotation.rb +21 -0
- data/lib/models/annotations/annotation_option.rb +9 -0
- data/lib/models/category.rb +26 -0
- data/lib/models/location.rb +30 -0
- data/lib/models/message.rb +9 -0
- data/lib/models/posting.rb +97 -0
- data/lib/models/posting_history.rb +8 -0
- data/lib/models/source.rb +27 -0
- data/lib/struct.rb +16 -0
- data/lib/threetaps-client.rb +44 -0
- data/spec/client/client_spec.rb +18 -0
- data/spec/client/geocoder_client_spec.rb +18 -0
- data/spec/client/posting_client_spec.rb +36 -0
- data/spec/client/reference_client_spec.rb +37 -0
- data/spec/client/search_client_spec.rb +53 -0
- data/spec/client/status_client_spec.rb +39 -0
- data/spec/dto/geocoder/geocoder_response_spec.rb +14 -0
- data/spec/dto/search/search_request_spec.rb +26 -0
- data/spec/dto/search/search_response_spec.rb +12 -0
- data/spec/spec_helper.rb +29 -0
- data/test/client/test_client.rb +11 -0
- data/test/client/test_geocoder_client.rb +43 -0
- data/test/client/test_posting_client.rb +88 -0
- data/test/client/test_reference_client.rb +32 -0
- data/test/client/test_search_client.rb +56 -0
- data/test/client/test_status_client.rb +49 -0
- data/test/dto/geocoder/test_geocoder_request.rb +16 -0
- data/test/dto/geocoder/test_geocoder_response.rb +14 -0
- data/test/dto/search/test_best_match_response.rb +10 -0
- data/test/dto/search/test_range_request.rb +13 -0
- data/test/dto/status/test_status_update_request.rb +18 -0
- data/test/helper.rb +18 -0
- data/test/models/test_posting.rb +28 -0
- data/test/test_struct.rb +17 -0
- data/test/test_threetaps-client.rb +7 -0
- data/threetaps-client.gemspec +153 -0
- metadata +266 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe PostingClient do
|
4
|
+
before(:all) do
|
5
|
+
end
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@posting_client = PostingClient.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return Posting object" do
|
12
|
+
stub_get_and_json_decode
|
13
|
+
@posting_client.get_posting("").is_a?(Posting).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
# no spec for creation - see tests
|
17
|
+
|
18
|
+
it "should return UpdateResponse object" do
|
19
|
+
stub_post_and_json_decode
|
20
|
+
UpdateResponse.should_receive(:from_hash).with([])
|
21
|
+
post = mock "Posting" , :to_json_for_update=>""
|
22
|
+
@posting_client.update_posting(post).class == UpdateResponse.class#).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return DeleteResponse object" do
|
26
|
+
stub_post_and_json_decode
|
27
|
+
DeleteResponse.should_receive(:from_hash).with([])
|
28
|
+
@posting_client.delete_posting("").class == DeleteResponse.class
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return boolean value" do
|
32
|
+
stub_post_and_json_decode
|
33
|
+
@posting_client.exists_posting(mock("")).should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ReferenceClient do
|
4
|
+
before(:each) do
|
5
|
+
@reference_client = ReferenceClient.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should send GET request and create Categories array from result" do
|
9
|
+
categories_response = mock "categories_array"
|
10
|
+
Category.should_receive(:from_array).and_return categories_response
|
11
|
+
|
12
|
+
@reference_client.get_categories.should == categories_response
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should send GET request and create Category from result" do
|
16
|
+
category_response = mock "category"
|
17
|
+
category_code = "VAUT"
|
18
|
+
Category.should_receive(:from_hash).and_return category_response
|
19
|
+
|
20
|
+
@reference_client.get_category(category_code).should == category_response
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should send GET request and create Locations array from result" do
|
24
|
+
locations_response = mock "locations_array"
|
25
|
+
Location.should_receive(:from_array).and_return locations_response
|
26
|
+
|
27
|
+
@reference_client.get_locations.should == locations_response
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should send GET request and create Sources array from result" do
|
31
|
+
sources_response = mock "sources_array"
|
32
|
+
Source.should_receive(:from_array).and_return sources_response
|
33
|
+
|
34
|
+
@reference_client.get_sources.should == sources_response
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe SearchClient do
|
4
|
+
before(:each) do
|
5
|
+
@search_client = SearchClient.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should send GET request and create SearchResponse from result" do
|
9
|
+
search_request = mock "search_request"
|
10
|
+
search_request.should_receive(:query_params)
|
11
|
+
search_response = mock "search_response"
|
12
|
+
SearchResponse.should_receive(:new).and_return search_response
|
13
|
+
|
14
|
+
@search_client.search(search_request).should == search_response
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should send GET request and create RangeResponse from result" do
|
18
|
+
stub_get_and_json_decode
|
19
|
+
range_request = mock "range_request"
|
20
|
+
range_request.should_receive(:query_params)
|
21
|
+
range_response = mock "range_response"
|
22
|
+
RangeResponse.should_receive(:from_array).and_return range_response
|
23
|
+
|
24
|
+
@search_client.range(range_request).should == range_response
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should send GET request and create SummaryResponse from result" do
|
28
|
+
summary_request = mock "summary_request"
|
29
|
+
summary_request.should_receive(:query_params)
|
30
|
+
summary_response = mock "summary_response"
|
31
|
+
SummaryResponse.should_receive(:from_hash).and_return summary_response
|
32
|
+
|
33
|
+
@search_client.summary(summary_request).should == summary_response
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should send GET request and create CountResponse from result" do
|
37
|
+
search_request = mock "search_request"
|
38
|
+
search_request.should_receive(:query_params)
|
39
|
+
count_response = mock "count_response"
|
40
|
+
CountResponse.should_receive(:new).and_return count_response
|
41
|
+
|
42
|
+
@search_client.count(search_request).should == count_response
|
43
|
+
end
|
44
|
+
it "should send GET request and create BestMatchResponse from result" do
|
45
|
+
keywords = ""
|
46
|
+
bestmatch_response = mock "bestmatch_response"
|
47
|
+
BestMatchResponse.should_receive(:from_hash).and_return bestmatch_response
|
48
|
+
|
49
|
+
@search_client.best_match(keywords).should == bestmatch_response
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe StatusClient do
|
4
|
+
before(:each) do
|
5
|
+
@status_client = StatusClient.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should send POST request and create Message from result" do
|
9
|
+
stub_post_and_json_decode
|
10
|
+
posting = mock "posting"
|
11
|
+
message = mock "message"
|
12
|
+
status_update_request = mock "status_update_request"
|
13
|
+
Message.should_receive(:new).and_return message
|
14
|
+
posting.should_receive(:status).and_return status_update_request
|
15
|
+
status_update_request.should_receive(:event).and_return ""
|
16
|
+
|
17
|
+
@status_client.update_status(posting).should == message
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should send POST request and create GetResponse from result" do
|
21
|
+
stub_post_and_json_decode
|
22
|
+
postings = mock "posting"
|
23
|
+
postings.should_receive(:to_json_for_status_client)
|
24
|
+
array = mock "array"
|
25
|
+
GetStatusResponse.should_receive(:from_array).and_return array
|
26
|
+
|
27
|
+
@status_client.get_status(postings).should == array
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should send GET request and create Message from result" do
|
31
|
+
stub_get_and_json_decode
|
32
|
+
message = mock "message"
|
33
|
+
Message.should_receive(:new).and_return message
|
34
|
+
|
35
|
+
@status_client.system_status.should == message
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
describe GeocoderResponse do
|
3
|
+
#before(:each) do
|
4
|
+
# @geocoder_response = Geocoder.new
|
5
|
+
#end
|
6
|
+
it "should initialize multiple objects form array" do
|
7
|
+
array = [1,2,3]
|
8
|
+
array.size.times do
|
9
|
+
GeocoderResponse.should_receive(:from_hash)
|
10
|
+
end
|
11
|
+
GeocoderResponse.from_array(array)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe SearchRequest do
|
4
|
+
before(:each) do
|
5
|
+
@search_request = SearchRequest.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return valid query params" do
|
9
|
+
@search_request.rpp = 20
|
10
|
+
@search_request.page = 14
|
11
|
+
#@search_request.source = 'SRC'
|
12
|
+
@search_request.category = 'STOO'
|
13
|
+
#@search_request.location = 'LOC'
|
14
|
+
#@search_request.heading = 'HD'
|
15
|
+
#@search_request.body = 'BD'
|
16
|
+
@search_request.text = 'BMW'
|
17
|
+
#@search_request.external_id = 'EXID'
|
18
|
+
#@search_request.start = Date.new(2011,4,10)
|
19
|
+
#@search_request.end = Date.new(2011,4,10)
|
20
|
+
@search_request.annotations = Hash["Status", 'for+free']
|
21
|
+
#@search_request.trusted_annotations = Hash["TR1", '1000', "TR2", '2000']
|
22
|
+
@search_request.retvals = ["category", "location", "heading", "externalURL", "timestamp", "postKey", "source", "image"]
|
23
|
+
@search_request.query_params.should_not == ""
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'supermodel'
|
5
|
+
require 'curb'
|
6
|
+
require 'threetaps-client'
|
7
|
+
require 'cgi'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def stub_json_decode
|
18
|
+
ActiveSupport::JSON.stub!(:decode).and_return []
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_get_and_json_decode
|
22
|
+
Curl::Easy.stub!(:new).and_return mock("Request", :perform => nil, :body_str => "")
|
23
|
+
stub_json_decode
|
24
|
+
end
|
25
|
+
|
26
|
+
def stub_post_and_json_decode
|
27
|
+
Curl::Easy.stub!(:http_post).and_return mock("Request", :perform => nil, :body_str => "")
|
28
|
+
stub_json_decode
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGeocoderClient < Test::Unit::TestCase
|
4
|
+
should "test coordinats geocode" do
|
5
|
+
geocoder_client = GeocoderClient.new
|
6
|
+
geocoder_request = GeocoderRequest.new
|
7
|
+
geocoder_request.latitude = '37.77493'
|
8
|
+
geocoder_request.longitude = '-122.41942'
|
9
|
+
request = geocoder_request
|
10
|
+
response = geocoder_client.geocode(request)
|
11
|
+
assert_equal Array, response.class
|
12
|
+
assert_equal GeocoderResponse, response.first.class
|
13
|
+
assert_equal "CAZ", response.first.code
|
14
|
+
end
|
15
|
+
|
16
|
+
should "test city geocode" do
|
17
|
+
geocoder_client = GeocoderClient.new
|
18
|
+
geocoder_request = GeocoderRequest.new
|
19
|
+
geocoder_request.city = 'los angeles'
|
20
|
+
request = geocoder_request
|
21
|
+
response = geocoder_client.geocode(request)
|
22
|
+
assert_equal Array, response.class
|
23
|
+
assert_equal GeocoderResponse, response.first.class
|
24
|
+
assert_equal "LAX", response.first.code
|
25
|
+
end
|
26
|
+
|
27
|
+
should "test both city and geocode" do
|
28
|
+
geocoder_client = GeocoderClient.new
|
29
|
+
geocoder_request1 = GeocoderRequest.new
|
30
|
+
geocoder_request1.latitude = '37.77493'
|
31
|
+
geocoder_request1.longitude = '-122.41942'
|
32
|
+
|
33
|
+
geocoder_request2 = GeocoderRequest.new
|
34
|
+
geocoder_request2.city = 'los angeles'
|
35
|
+
|
36
|
+
request = [geocoder_request1, geocoder_request2]
|
37
|
+
response = geocoder_client.geocode(request)
|
38
|
+
assert_equal Array, response.class
|
39
|
+
assert_equal GeocoderResponse, response.first.class
|
40
|
+
assert_equal "CAZ", response.first.code
|
41
|
+
assert_equal "LAX", response[1].code
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPostingClient < Test::Unit::TestCase
|
4
|
+
should "test single posting creation and deletion" do
|
5
|
+
keys = []
|
6
|
+
client = PostingClient.new
|
7
|
+
posting = Posting.new(
|
8
|
+
:source => "3TAPS",
|
9
|
+
:heading => "Svitla posting",
|
10
|
+
:timestamp => Time.now
|
11
|
+
)
|
12
|
+
response = client.create_posting(posting)
|
13
|
+
assert_equal Array, response.class
|
14
|
+
assert_equal CreateResponse, response.first.class
|
15
|
+
assert_nil response.first.error
|
16
|
+
posting_key = response.first.post_key
|
17
|
+
posting.heading = "Svitla posting +++#{rand(100)}+++"
|
18
|
+
posting.postKey = posting_key
|
19
|
+
posting.body = "posting"
|
20
|
+
|
21
|
+
response = client.update_posting(posting)
|
22
|
+
assert_equal true, response.success
|
23
|
+
|
24
|
+
keys << posting_key
|
25
|
+
|
26
|
+
posting = Posting.new(
|
27
|
+
:source => "3TAPS",
|
28
|
+
:heading => "Svitla posting",
|
29
|
+
:timestamp => Time.now
|
30
|
+
)
|
31
|
+
response = client.create_posting(posting)
|
32
|
+
assert_equal Array, response.class
|
33
|
+
assert_equal CreateResponse, response.first.class
|
34
|
+
assert_nil response.first.error
|
35
|
+
posting_key = response.first.post_key
|
36
|
+
|
37
|
+
keys << posting_key
|
38
|
+
|
39
|
+
response = client.delete_posting(keys)
|
40
|
+
assert_equal DeleteResponse, response.class
|
41
|
+
assert_equal true, response.success
|
42
|
+
end
|
43
|
+
|
44
|
+
should "test multiple postings creation and deletion" do
|
45
|
+
client = PostingClient.new
|
46
|
+
posting1 = Posting.new(
|
47
|
+
:source => "3TAPS",
|
48
|
+
:heading => "Svitla posting1",
|
49
|
+
:timestamp => Time.now
|
50
|
+
)
|
51
|
+
posting2 = Posting.new(
|
52
|
+
:source => "3TAPS",
|
53
|
+
:heading => "Svitla posting2",
|
54
|
+
:timestamp => Time.now
|
55
|
+
)
|
56
|
+
response = client.create_posting([posting1, posting2])
|
57
|
+
assert_equal Array, response.class
|
58
|
+
assert_equal CreateResponse, response.first.class
|
59
|
+
assert_nil response.first.error
|
60
|
+
|
61
|
+
posting_key = response[0].post_key
|
62
|
+
posting1.postKey = posting_key
|
63
|
+
posting_key = response[1].post_key
|
64
|
+
posting2.postKey = posting_key
|
65
|
+
posting1.body = "posting1"
|
66
|
+
posting2.body = "posting2"
|
67
|
+
response = client.update_posting([posting1, posting2])
|
68
|
+
assert_equal true, response.success
|
69
|
+
|
70
|
+
keys = [posting1.postKey, posting2.postKey]
|
71
|
+
response = client.delete_posting(keys)
|
72
|
+
assert_equal DeleteResponse, response.class
|
73
|
+
assert_equal true, response.success
|
74
|
+
end
|
75
|
+
|
76
|
+
should "test posting retrieval" do
|
77
|
+
client = PostingClient.new
|
78
|
+
posting = client.get_posting("BF87BFW")
|
79
|
+
assert_equal Posting, posting.class
|
80
|
+
assert_equal "BF87BFW", posting.postKey
|
81
|
+
end
|
82
|
+
|
83
|
+
should "test posting deletion" do
|
84
|
+
client = PostingClient.new
|
85
|
+
result = client.delete_posting('post_key')
|
86
|
+
assert_equal DeleteResponse, result.class
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestReferenceClient < Test::Unit::TestCase
|
4
|
+
should "test get categories" do
|
5
|
+
client = ReferenceClient.new
|
6
|
+
categories = client.get_categories
|
7
|
+
assert_equal Array, categories.class
|
8
|
+
assert_equal Category, categories.first.class
|
9
|
+
end
|
10
|
+
|
11
|
+
should "test get category" do
|
12
|
+
client = ReferenceClient.new
|
13
|
+
category = client.get_category("VAUT")
|
14
|
+
assert_equal "VAUT", category.code
|
15
|
+
assert_equal "Autos", category.category
|
16
|
+
assert_equal "Vehicles", category.group
|
17
|
+
end
|
18
|
+
|
19
|
+
should "test get locations" do
|
20
|
+
client = ReferenceClient.new
|
21
|
+
locations = client.get_locations
|
22
|
+
assert_equal Array, locations.class
|
23
|
+
assert_equal Location, locations.first.class
|
24
|
+
end
|
25
|
+
|
26
|
+
should "test get sources" do
|
27
|
+
client = ReferenceClient.new
|
28
|
+
sources = client.get_sources
|
29
|
+
assert_equal Array, sources.class
|
30
|
+
assert_equal Source, sources.first.class
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSearchClient < Test::Unit::TestCase
|
4
|
+
should "get the range request result" do
|
5
|
+
range_request = RangeRequest.new
|
6
|
+
search_request = SearchRequest.new
|
7
|
+
search_request.category = 'VAUT'
|
8
|
+
search_request.annotations = {:Make => "porsche"}
|
9
|
+
range_request.search_request = search_request
|
10
|
+
range_request.fields = ['price', 'year']
|
11
|
+
client = SearchClient.new
|
12
|
+
range_response = client.range(range_request)
|
13
|
+
assert_equal RangeResponse, range_response.class
|
14
|
+
assert_equal range_request.fields, range_response.ranges.collect{|r| r['field']}
|
15
|
+
end
|
16
|
+
|
17
|
+
should "get the search request result" do
|
18
|
+
search_request = SearchRequest.new
|
19
|
+
search_request.category = 'VAUT'
|
20
|
+
search_request.rpp = 2
|
21
|
+
search_request.annotations = {:Make => "porsche"}
|
22
|
+
client = SearchClient.new
|
23
|
+
search_response = client.search(search_request)
|
24
|
+
assert_equal SearchResponse, search_response.class
|
25
|
+
assert_equal Array, search_response.results.class
|
26
|
+
assert_equal Posting, search_response.results.first.class
|
27
|
+
end
|
28
|
+
|
29
|
+
should "get the count request result" do
|
30
|
+
search_request = SearchRequest.new
|
31
|
+
search_request.category = 'VAUT'
|
32
|
+
search_request.annotations = {:Make => "porsche"}
|
33
|
+
client = SearchClient.new
|
34
|
+
count_response = client.count(search_request)
|
35
|
+
assert_equal CountResponse, count_response.class
|
36
|
+
assert_not_equal nil , count_response.count
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
should "get the summary result" do
|
41
|
+
search_request = SearchRequest.new
|
42
|
+
search_request.category = 'VAUT'
|
43
|
+
search_request.annotations = {:Make => "porsche"}
|
44
|
+
client = SearchClient.new
|
45
|
+
summary_response = client.summary(search_request)
|
46
|
+
assert_equal SummaryResponse, summary_response.class
|
47
|
+
end
|
48
|
+
|
49
|
+
should "get the best match result" do
|
50
|
+
search_keywords = "iPad,Apple,iPhone"
|
51
|
+
client = SearchClient.new
|
52
|
+
best_match_response = client.best_match(search_keywords)
|
53
|
+
assert_equal BestMatchResponse, best_match_response.class
|
54
|
+
assert_equal 'SELE', best_match_response.category
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestStatusClient < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "get status for posting with BD9FHQC postKey" do
|
6
|
+
posting_client = PostingClient.new
|
7
|
+
existing_postings = posting_client.get_posting("BD9FHQC")
|
8
|
+
client = StatusClient.new
|
9
|
+
response = client.get_status(existing_postings)
|
10
|
+
assert_equal Array, response.class
|
11
|
+
end
|
12
|
+
|
13
|
+
should "test update status" do
|
14
|
+
posting_client = PostingClient.new
|
15
|
+
status_client = StatusClient.new
|
16
|
+
posting = posting_client.get_posting("BD9FHQC")
|
17
|
+
error = Message.from_hash(:code => 666, :message => "UFO posting error")
|
18
|
+
posting.status.errors << error
|
19
|
+
posting.status.attributes = {:postKey => "TESTKEY", :message => "UFO test message"}
|
20
|
+
posting.status.event = 'lost'
|
21
|
+
assert_equal String, posting.status.to_params.class
|
22
|
+
update_response = status_client.update_status(posting)
|
23
|
+
assert_equal Message , update_response.class
|
24
|
+
assert_equal 200 , update_response.code
|
25
|
+
end
|
26
|
+
|
27
|
+
should "test get status" do
|
28
|
+
search_request = SearchRequest.new
|
29
|
+
search_request.category = 'VAUT'
|
30
|
+
search_request.annotations = {:Make => "porsche"}
|
31
|
+
search_request.rpp = 2
|
32
|
+
search_request.page = 4
|
33
|
+
search_request.retvals = ["category", "location", "heading", "externalURL", "timestamp", "postKey", "source", "image", "externalID"]
|
34
|
+
|
35
|
+
client = SearchClient.new
|
36
|
+
search_response = client.search(search_request)
|
37
|
+
existing_postings = search_response.results
|
38
|
+
client = StatusClient.new
|
39
|
+
response = client.get_status(existing_postings)
|
40
|
+
assert_equal Array, response.class
|
41
|
+
end
|
42
|
+
|
43
|
+
should "test system status" do
|
44
|
+
client = StatusClient.new
|
45
|
+
status_response = client.system_status
|
46
|
+
assert_equal Message, status_response.class
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGeoCoderRequest < Test::Unit::TestCase
|
4
|
+
should "receive params and perform them" do
|
5
|
+
geocoder_request = GeocoderRequest.new
|
6
|
+
geocoder_request.latitude = '12'
|
7
|
+
geocoder_request.longitude = '12'
|
8
|
+
geocoder_request.country = 'US'
|
9
|
+
geocoder_request.state = 'CA'
|
10
|
+
geocoder_request.city = 'Palo Alto'
|
11
|
+
geocoder_request.locality = 'unknown'
|
12
|
+
geocoder_request.postal = '90001'
|
13
|
+
geocoder_request.text = 'custom message here'
|
14
|
+
assert_equal String, geocoder_request.to_params.class
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGeoCoderResponse < Test::Unit::TestCase
|
4
|
+
should "receive an array and perform it into hash" do
|
5
|
+
geocoder_response = GeocoderResponse.from_array([['TEST','123.9876','-123.98765'],['TEST','123.9876','-123.98765']])
|
6
|
+
assert_equal Array, geocoder_response.class
|
7
|
+
geocoder_response.each do |geocode|
|
8
|
+
assert_equal GeocoderResponse, geocode.class
|
9
|
+
assert_equal 'TEST', geocode.code
|
10
|
+
assert_equal '123.9876', geocode.latitude
|
11
|
+
assert_equal '-123.98765', geocode.longitude
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestBestMatchResponse < Test::Unit::TestCase
|
4
|
+
should "get numResults attribute" do
|
5
|
+
response = BestMatchResponse.from_hash("numResults" => 200, "category" => "VAULT")
|
6
|
+
assert_equal 200, response.numResults
|
7
|
+
assert_equal 200, response.num_results
|
8
|
+
assert_equal "VAULT", response.category
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRangeRequest < Test::Unit::TestCase
|
4
|
+
should "return valid http params string" do
|
5
|
+
search_request = SearchRequest.new()
|
6
|
+
search_request.category = 'VAUT'
|
7
|
+
search_request.annotations = {:Make => "porsche"}
|
8
|
+
range_request = RangeRequest.from_hash(:search_request => search_request, :fields => ["year","price"])
|
9
|
+
assert_equal RangeRequest, range_request.class
|
10
|
+
assert_equal SearchRequest, range_request.search_request.class
|
11
|
+
assert_equal String, range_request.query_params.class
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestStatusUpdateRequest < Test::Unit::TestCase
|
4
|
+
should "Test update status request methods" do
|
5
|
+
posting = Posting.new(:externalID => "1234567890", :source => '3TAPS')
|
6
|
+
assert_equal "source:'3TAPS', externalID:1234567890", posting.to_json_for_status_client
|
7
|
+
assert_equal StatusUpdateRequest, posting.status.class
|
8
|
+
assert_equal Array, posting.status.errors.class
|
9
|
+
assert_equal Hash, posting.status.attributes.class
|
10
|
+
|
11
|
+
error = Message.from_hash(:code => 666, :message => "UFO posting error")
|
12
|
+
posting.status.errors << error
|
13
|
+
posting.status.attributes = {:postKey => "TESTKEY", :message => "UFO test message"}
|
14
|
+
posting.status.event = 'lost'
|
15
|
+
assert_equal String, posting.status.to_params.class
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'threetaps-client'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestPosting < Test::Unit::TestCase
|
4
|
+
should "create posting with empty images array" do
|
5
|
+
posting = Posting.new
|
6
|
+
assert_equal [], posting.images
|
7
|
+
assert_equal({}, posting.annotations)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "create posting with empty status attribute" do
|
11
|
+
posting = Posting.new
|
12
|
+
assert_equal StatusUpdateRequest, posting.status.class
|
13
|
+
assert_equal String, posting.status.event.class
|
14
|
+
assert_equal Hash, posting.status.attributes.class
|
15
|
+
assert_equal Array, posting.status.errors.class
|
16
|
+
end
|
17
|
+
|
18
|
+
should "create posting with not empty images array" do
|
19
|
+
posting = Posting.new(
|
20
|
+
:images => ["image_path"],
|
21
|
+
:history => ["old_posting"],
|
22
|
+
:annotations => {'annotation' => "value"}
|
23
|
+
)
|
24
|
+
assert_equal ["image_path"], posting.images
|
25
|
+
assert_equal ["old_posting"], posting.history
|
26
|
+
assert_equal({'annotation' => "value"}, posting.annotations)
|
27
|
+
end
|
28
|
+
end
|