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.
Files changed (66) hide show
  1. data/Gemfile +17 -0
  2. data/Gemfile.lock +43 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.rdoc +48 -0
  5. data/Rakefile +68 -0
  6. data/VERSION +1 -0
  7. data/lib/client/client.rb +43 -0
  8. data/lib/client/geocoder_client.rb +42 -0
  9. data/lib/client/posting_client.rb +88 -0
  10. data/lib/client/reference_client.rb +60 -0
  11. data/lib/client/search_client.rb +82 -0
  12. data/lib/client/status_client.rb +72 -0
  13. data/lib/dto/geocoder/geocoder_request.rb +16 -0
  14. data/lib/dto/geocoder/geocoder_response.rb +7 -0
  15. data/lib/dto/posting/create_response.rb +23 -0
  16. data/lib/dto/posting/delete_response.rb +9 -0
  17. data/lib/dto/posting/exists_response.rb +16 -0
  18. data/lib/dto/posting/update_response.rb +9 -0
  19. data/lib/dto/search/best_match_response.rb +20 -0
  20. data/lib/dto/search/count_response.rb +9 -0
  21. data/lib/dto/search/query_request +0 -0
  22. data/lib/dto/search/range_request.rb +23 -0
  23. data/lib/dto/search/range_response.rb +26 -0
  24. data/lib/dto/search/search_request.rb +79 -0
  25. data/lib/dto/search/search_response.rb +37 -0
  26. data/lib/dto/search/summary_request.rb +13 -0
  27. data/lib/dto/search/summary_response.rb +20 -0
  28. data/lib/dto/status/get_status_response.rb +43 -0
  29. data/lib/dto/status/status_update_request.rb +27 -0
  30. data/lib/models/annotations/annotation.rb +21 -0
  31. data/lib/models/annotations/annotation_option.rb +9 -0
  32. data/lib/models/category.rb +26 -0
  33. data/lib/models/location.rb +30 -0
  34. data/lib/models/message.rb +9 -0
  35. data/lib/models/posting.rb +97 -0
  36. data/lib/models/posting_history.rb +8 -0
  37. data/lib/models/source.rb +27 -0
  38. data/lib/struct.rb +16 -0
  39. data/lib/threetaps-client.rb +44 -0
  40. data/spec/client/client_spec.rb +18 -0
  41. data/spec/client/geocoder_client_spec.rb +18 -0
  42. data/spec/client/posting_client_spec.rb +36 -0
  43. data/spec/client/reference_client_spec.rb +37 -0
  44. data/spec/client/search_client_spec.rb +53 -0
  45. data/spec/client/status_client_spec.rb +39 -0
  46. data/spec/dto/geocoder/geocoder_response_spec.rb +14 -0
  47. data/spec/dto/search/search_request_spec.rb +26 -0
  48. data/spec/dto/search/search_response_spec.rb +12 -0
  49. data/spec/spec_helper.rb +29 -0
  50. data/test/client/test_client.rb +11 -0
  51. data/test/client/test_geocoder_client.rb +43 -0
  52. data/test/client/test_posting_client.rb +88 -0
  53. data/test/client/test_reference_client.rb +32 -0
  54. data/test/client/test_search_client.rb +56 -0
  55. data/test/client/test_status_client.rb +49 -0
  56. data/test/dto/geocoder/test_geocoder_request.rb +16 -0
  57. data/test/dto/geocoder/test_geocoder_response.rb +14 -0
  58. data/test/dto/search/test_best_match_response.rb +10 -0
  59. data/test/dto/search/test_range_request.rb +13 -0
  60. data/test/dto/status/test_status_update_request.rb +18 -0
  61. data/test/helper.rb +18 -0
  62. data/test/models/test_posting.rb +28 -0
  63. data/test/test_struct.rb +17 -0
  64. data/test/test_threetaps-client.rb +7 -0
  65. data/threetaps-client.gemspec +153 -0
  66. metadata +266 -0
@@ -0,0 +1,20 @@
1
+ # Class BestMatchResponse represents server response on +best_match+ Search API
2
+ # request. Server response is sent to initializer which creates objects with
3
+ # attributes +category+, +numResults+ accessible via getters:
4
+ # * +category+
5
+ # * +num_results+
6
+ # * +numResults+
7
+ #
8
+ # Examples:
9
+ #
10
+ # response = BestMatchResponse.new("category" => "VAUT", "numResults" => 20)
11
+ # response.category # => "VAUT"
12
+ # response.numResults # => 20
13
+ # response.num_results # => 20
14
+ #
15
+ class BestMatchResponse < Struct.new(:category, :numResults) do
16
+ def num_results
17
+ numResults
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ # Class CountResponse represents server response on +count+ Search API
2
+ # request. Server response is sent to initializer which creates objects with
3
+ # attribute +count+ accessible via getter:
4
+ #
5
+ # response = CountResponse.new("count" => 20)
6
+ # response.count # => 20
7
+ #
8
+ class CountResponse < Struct.new(:count)
9
+ end
File without changes
@@ -0,0 +1,23 @@
1
+ # Returns the minium and maximum values currently in 3taps for the given fields
2
+ # that match the given Common Search Criteria. The purpose of the range method
3
+ # is to provide developers with sensible values for range-based UI filters.
4
+ #
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 = ['year', 'price']
11
+ #
12
+ class RangeRequest < Struct.new(:search_request, :fields)
13
+
14
+ def add_field(field)
15
+ fields << field
16
+ end
17
+
18
+ def query_params
19
+ query_params = search_request.query_params
20
+ query_params += "fields=#{CGI.escape(fields.join(','))}"
21
+ query_params
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # Class RangeResponse represents server response on +range+ Search API
2
+ # request. Server response is sent to +from_array+ method which creates objects
3
+ # with attribute +ranges+ accessible via getter:
4
+ #
5
+ # response = RangeResponse.from_array(...)
6
+ # response.ranges # => Array
7
+ #
8
+ class RangeResponse < Struct.new(:ranges)
9
+
10
+ # Class Range represents elements of server response on +range+ Search API
11
+ # request. Server response is sent to initializer which creates object
12
+ # with attributes +field+, +min+, +max+ accessible via getters:
13
+ #
14
+ # range = Range.new(...)
15
+ # range.field # => Array
16
+ # range.min # => 10
17
+ # range.max # => 20
18
+ #
19
+ class Range < Struct.new(:field, :min, :max)
20
+ end
21
+
22
+ # Method +from_array+ creates RangeResponse object with a set of Range objects.
23
+ def self.from_array(json)
24
+ self.from_hash(:ranges => json.collect { |key, value| Range.from_hash( :field => key, :max => value["max"], :min => value["min"])})
25
+ end
26
+ end
@@ -0,0 +1,79 @@
1
+ class SearchRequest
2
+ # annotations attribute should be a Hash object
3
+ attr_accessor :rpp, :page, :source, :category, :location, :heading,
4
+ :body, :text, :external_id, :start, :end, :annotations,
5
+ :trusted_annotations, :retvals
6
+
7
+ def add_retval(retval)
8
+ @retvals << retval
9
+ end
10
+
11
+ def query_params
12
+ query = Hash.new
13
+ url_params = ''
14
+ if (rpp != nil)
15
+ query[:rpp] = rpp.to_s;
16
+ url_params += "rpp=#{CGI.escape(query[:rpp])}&"
17
+ end
18
+ if (page != nil)
19
+ query[:page] = page.to_s;
20
+ url_params += "page=#{CGI.escape(query[:page])}&"
21
+ end
22
+ if (source != nil)
23
+ query[:source] = source.to_s;
24
+ url_params += "source=#{CGI.escape(query[:source])}&"
25
+ end
26
+ if (category != nil)
27
+ query[:category] = category.to_s;
28
+ url_params += "category=#{CGI.escape(query[:category])}&"
29
+ end
30
+ if (location != nil)
31
+ query[:location] = location.to_s;
32
+ url_params += "location=#{CGI.escape(query[:location])}&"
33
+ end
34
+ if (heading != nil)
35
+ query[:heading] = heading.to_s;
36
+ url_params += "heading=#{CGI.escape(query[:heading])}&"
37
+ end
38
+ if (body != nil)
39
+ query[:body] = body.to_s;
40
+ url_params += "body=#{CGI.escape(query[:body])}&"
41
+ end
42
+ if (text != nil)
43
+ query[:text] = text.to_s;
44
+ url_params += "text=#{CGI.escape(query[:text])}&"
45
+ end
46
+ if (external_id != nil)
47
+ query[:external_id] = external_id.to_s;
48
+ url_params += "external_id=#{CGI.escape(query[:external_id])}&"
49
+ end
50
+ if (start != nil)
51
+ query[:start] = start.to_s;
52
+ url_params += "start=#{CGI.escape(query[:start])}&"
53
+ end
54
+ if (self.end != nil)
55
+ query[:end] = self.end.to_s;
56
+ url_params += "end=#{CGI.escape(query[:end])}&"
57
+ end
58
+
59
+ if (annotations != nil && annotations.size > 0)
60
+ # query[:annotations] = ActiveSupport::JSON.encode(annotations)
61
+ query[:annotations] = annotations
62
+ # query.each do |key, value|
63
+ # url_params += "#{key}=#{value}&"
64
+ # end
65
+ url_params += "annotations=#{CGI.escape(ActiveSupport::JSON.encode(query[:annotations]))}&" #'annotations=#{CGI.escape(ActiveSupport::JSON.encode(search.annotations))}'
66
+ end
67
+ if (trusted_annotations != nil && trusted_annotations.size > 0)
68
+ #query[:trusted_annotations] = ActiveSupport::JSON.encode(trusted_annotations)
69
+ query[:trusted_annotations] = trusted_annotations
70
+ url_params += "trusted_annotations=#{CGI.escape(ActiveSupport::JSON.encode(query[:trusted_annotations]))}&"
71
+ end
72
+ if (retvals != nil)
73
+ query[:retvals] = retvals.join(',') #queryParams.put("retvals", Utils.join(retvals));
74
+ url_params += "retvals=#{CGI.escape(query[:retvals])}&"
75
+ end
76
+
77
+ url_params
78
+ end
79
+ end
@@ -0,0 +1,37 @@
1
+ # Class SearchResponse represents server response on +search+ Search API
2
+ # request. Server response is sent to initializer which creates object with
3
+ # attributes +success+, +numResults+, +execTimeMs+, +results+ accessible via getters:
4
+ # * +success+
5
+ # * +num_results+
6
+ # * +numResults+
7
+ # * +execTimeMs+
8
+ # * +exec_time_ms+
9
+ # * +results+
10
+ #
11
+ # Examples:
12
+ #
13
+ # response = SearchResponse.new("success" => "true", "numResults" => 0, "execTimeMs" => 100, "results" => [])
14
+ # response.category # => "VAUT"
15
+ # response.numResults # => 0
16
+ # response.num_results # => 0
17
+ # response.execTimeMs # => 100
18
+ # response.exec_time_ms # => 100
19
+ # response.results # => []
20
+ #
21
+ class SearchResponse < Struct.new(:success, :numResults, :execTimeMs, :results) do
22
+ def num_results
23
+ numResults
24
+ end
25
+ def exec_time_ms
26
+ execTimeMs
27
+ end
28
+ end
29
+
30
+ # Initializer receives hash as a parameter and fills object fields from it.
31
+ # +results+ field is filled with array of Posting objects.
32
+ def initialize(hash = {})
33
+ hash.each do |key, value|
34
+ self.send("#{key}=".to_sym, key == 'results' ? value.collect {|item| Posting.new(item)} : value )
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ #private SearchRequest searchRequest;
2
+ #private String dimension;
3
+ class SummaryRequest
4
+ attr_accessor :search_request, :dimension
5
+
6
+ def query_params
7
+ query_params = ''
8
+ query_params = "dimension=#{CGI.escape(dimension)}&" if (dimension != nil)
9
+ query_params += search_request.query_params if (search_request != nil)
10
+ query_params
11
+ end
12
+
13
+ end
@@ -0,0 +1,20 @@
1
+ # Class SummaryResponse represents server response on +summary+ Search API
2
+ # request. Server response is sent to initializer which creates object with
3
+ # attributes +totals+, +execTimeMs+ accessible via getters:
4
+ # * +totals+
5
+ # * +execTimeMs+
6
+ # * +exec_time_ms+
7
+ #
8
+ # Examples:
9
+ #
10
+ # response = SummaryResponse.new("totals" => 20, "execTimeMs" => 100)
11
+ # response.totals # => 20
12
+ # response.execTimeMs # => 100
13
+ # response.exec_time_ms # => 100
14
+ #
15
+ class SummaryResponse < Struct.new(:totals, :execTimeMs) do
16
+ def exec_time_ms
17
+ execTimeMs
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ # Class GetStatusResponse represents server response on +get_status+ Status API
2
+ # request. Server response is sent to +from_array+ method which creates objects
3
+ # attributes +exists+, +externalID+, +source+, +history+ accessible via getters:
4
+ # * +exists+
5
+ # * +externalID+
6
+ # * +source+
7
+ # * +history+
8
+ #
9
+ # Example:
10
+ #
11
+ # response = GetStatusResponse.from_array(...) # => Array
12
+ #
13
+ class GetStatusResponse < Struct.new(:exists, :externalID, :source, :history)
14
+ # Class Status represents elements of server response on +get_status+ Status API
15
+ # request. Server response is sent to initializer which creates object
16
+ # with attributes +field+, +attrs+ accessible via getters:
17
+ #
18
+ # status = Status.new(...)
19
+ # status.field # => Array
20
+ # status.attrs # => Array of Attr
21
+ #
22
+ class Status < Struct.new(:field, :attrs)
23
+ end
24
+ # Class Attr represents elements of server response on +get_status+ Status API
25
+ # request. Server response is sent to initializer which creates object
26
+ # with attributes +timestamp+, +errors+, +attributes+ accessible via getters:
27
+ #
28
+ # attr = Attr.new(...)
29
+ #
30
+ class Attr < Struct.new(:timestamp, :errors, :attributes)
31
+ end
32
+ # Method +from_array+ creates GetStatusResponse object
33
+ def self.from_array(json)
34
+ json.each do |hash|
35
+ hash.each do |key, value|
36
+ self.new("#{key}=".to_sym, key == 'history' ? value.collect {
37
+ |key, items| Status.new(:field => key, :attrs => items.collect {|item|
38
+ Attr.new(:timestamp => item["timestamp"], :errors => item["errors"], :attributes => item["attributes"]) }
39
+ )} : value )
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ # Class StatusUpdateRequest returns the correct string for request 3taps
2
+ #
3
+ class StatusUpdateRequest < Struct.new(:event, :timestump, :attributes, :errors)
4
+ #
5
+ # Method +to_params+ creates the correct string for request 3taps.
6
+ #
7
+ def to_params
8
+ data = "status:'#{event}'"
9
+ data << ", timestump:'#{((timestump).utc.to_s(:db)).gsub(/\s/,"+")}'" if timestump
10
+ data << ", attributes:{#{attributes_for_params}}" unless attributes.empty?
11
+ data << ", errors:[#{errors_for_params}]" unless errors.empty?
12
+ data
13
+ end
14
+ #
15
+ # Method +attributes_for_params+ creates array attributes for params.
16
+ #
17
+ def attributes_for_params
18
+ attributes.collect{ |key, value| "#{key}:'#{CGI.escape value}'" }.join(", ")
19
+ end
20
+ #
21
+ # Method +errors_for_params+ array errors for params.
22
+ #
23
+ def errors_for_params
24
+ errors.collect{ |error| "{code:#{error.code}, message:'#{CGI.escape error.message}'}" }.join(", ")
25
+ end
26
+
27
+ end
@@ -0,0 +1,21 @@
1
+ # Class Annotation represents structure of annotation
2
+ #
3
+ # annotation = Annotation.new
4
+ # annotation.name # => String
5
+ # annotation.annotation_type # => String
6
+ # annotation.options # => Array of AnnotationOption objects
7
+ #
8
+ class Annotation < SuperModel::Base
9
+ attributes :name, :annotation_type, :options
10
+
11
+ # Class AnnotaionType represents container of constants of annotation types:
12
+ # SELECT = 1
13
+ # STRING = 2
14
+ # NUMBER = 3
15
+ #
16
+ class AnnotaionType
17
+ SELECT = 1
18
+ STRING = 2
19
+ NUMBER = 3
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # Class AnnotationOption represents structure of options
2
+ #
3
+ # option = AnnotationOption.new
4
+ # option.value # => String
5
+ # option.sub_annotation # => String
6
+ #
7
+ class AnnotationOption < SuperModel::Base
8
+ attributes :value, :sub_annotation
9
+ end
@@ -0,0 +1,26 @@
1
+ # Class Category represents structure of category:
2
+ #
3
+ # category = Category.new
4
+ # category.code # => String
5
+ # category.group # => String
6
+ # category.category # => String
7
+ # category.hidden # => Boolean
8
+ # category.annotations # => Array of Annotation objects
9
+
10
+ # category.from_array(array) # => Array of Category objects
11
+ #
12
+ class Category < Struct.new(:group, :category, :code, :annotations, :hidden)
13
+
14
+ # Method +from_array+ returns array of categories(create from json).
15
+ # Takes value of array objects as json parameter array.
16
+ #
17
+ # Example:
18
+ #
19
+ # Category.from_array([...array of JSON objects...]) # => Array of Category
20
+ #
21
+ def self.from_array(array)
22
+ array.collect do |element|
23
+ Category.new(element)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # Class Location represents structure of location:
2
+ #
3
+ # location = Location.new
4
+ # location.countryRank # => Integer
5
+ # location.country # => String
6
+ # location.cityRank # => Integer
7
+ # location.city # => String
8
+ # location.stateCode # => String
9
+ # location.stateName # => String
10
+ # location.code # => String
11
+ # location.latitude # => Float
12
+ # location.longitude # => Float
13
+ #
14
+ # location.from_array(array) # => Array of Location objects
15
+ #
16
+ class Location < Struct.new(:countryRank, :country, :cityRank, :city, :stateCode, :stateName, :code, :latitude, :longitude)
17
+
18
+ # Method +from_array+ returns array of locations(create from json).
19
+ # Takes value of array objects as json parameter array.
20
+ #
21
+ # Example:
22
+ #
23
+ # Location.from_array([...array of JSON objects...]) # => Array of Location
24
+ #
25
+ def self.from_array(array)
26
+ array.collect do |element|
27
+ Location.new(element)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ # Class Message represents structure of message
2
+ #
3
+ # message = Message.new
4
+ # message.code # => Integer
5
+ # message.message # => String
6
+ #
7
+ class Message < Struct.new(:code, :message)
8
+
9
+ end
@@ -0,0 +1,97 @@
1
+ # Class Posting represents structure of posting:
2
+ #
3
+ # posting = Posting.new
4
+ # posting.postKey # => String
5
+ # posting.heading # => String
6
+ # posting.body # => String
7
+ # posting.category # => Boolean
8
+ # posting.source # => Array of Annotation objects
9
+ # posting.location # => String
10
+ # posting.longitude # => Float
11
+ # posting.latitude # => Float
12
+ # posting.language # => String
13
+ # posting.price # => String
14
+ # posting.currency # => String
15
+ # posting.images # => Array of String objects
16
+ # posting.externalURL # => String
17
+ ## posting.externalID # => String
18
+ # posting.accountName # => String
19
+ # posting.accountID # => String
20
+ # posting.clickCount # => Integer
21
+ # posting.timestamp # => Date
22
+ # posting.expiration # => Date
23
+ # posting.indexed # => Date
24
+ # posting.trustedAnnotations # => Array of Annotation objects
25
+ # posting.annotations # => Array of Annotation objects
26
+ # posting.errors # => Array of String objects
27
+ # posting.status # => String
28
+ # posting.history # => String
29
+
30
+ # posting.to_json # => Array of JSON objects
31
+ # posting.to_json_for_update # => Array of JSON objects
32
+ # posting.to_json_for_status_client # => Array of JSON objects
33
+ # posting.to_json_for_status # => Array of JSON objects
34
+ class Posting < SuperModel::Base
35
+ attributes :postKey, :heading, :body, :category, :source, :location,
36
+ :longitude, :latitude, :language, :price, :currency, :images,
37
+ :externalURL, :externalID, :accountName, :accountID, :clickCount,
38
+ :timestamp, :expiration, :indexed, :trustedAnnotations,
39
+ :annotations, :errors, :status, :history
40
+
41
+ def initialize(*params)
42
+ super(*params)
43
+ @attributes[:images] ||= []
44
+ @attributes[:annotations] ||= {}
45
+ @attributes[:status] ||= StatusUpdateRequest.from_hash(:event => '', :timestump => nil, :attributes => {}, :errors => [])
46
+ end
47
+
48
+ def to_json
49
+ posting = "{"+'source:'+"'#{self.source}'" + ',category:' + "'#{self.category}'" + ',location:' + "'#{self.location}'" + ',heading:' + "'#{CGI.escape self.heading}'"
50
+ posting << ",timestamp: '#{(Time.now.utc.to_s(:db)).gsub(/\s/,"+")}'"
51
+ posting << ',images:' + "[#{images.collect{ |image| "'#{image}'"}.join(',')}]"
52
+ if self.body.present?
53
+ posting << ',body:' + "'#{CGI.escape self.body}'"
54
+ end
55
+ if self.annotations
56
+ annotations = []
57
+ self.annotations.each{|k,v| annotations << "#{k}:" + "'#{v}'"}
58
+ posting << ',annotations:' + "[{#{annotations.join(',')}}]"
59
+ end
60
+ posting + "}"
61
+ end
62
+
63
+ def to_json_for_update
64
+ data = "['#{self.postKey}',"
65
+ data << "{heading:"+ "'#{CGI.escape self.heading}'"
66
+ data << ",images:" + "[#{images.collect{ |image| "'#{image}'"}.join(',')}]"
67
+ data << ",source:'#{self.source}'" unless self.source.blank?
68
+ data << ",category:'#{self.category}'" unless self.category.blank?
69
+ data << ",location:'#{self.location}'" unless self.location.blank?
70
+ if self.body.present?
71
+ data << ",body:" + "'#{CGI.escape self.body}'"
72
+ end
73
+ if self.annotations
74
+ annotations = []
75
+ self.annotations.each{|k,v| annotations << "#{k}:" + "'#{v}'"}
76
+ data << ",annotations:" + "[{#{annotations.join(',')}}]"
77
+ end
78
+ data << "}"
79
+ data << "]"
80
+ end
81
+
82
+ def to_json_for_status
83
+ # {source: 'CRAIG', externalID: 3434399120}
84
+ data = "{source: '"
85
+ data << self.source || " "
86
+ data << "', externalID: "
87
+ data << self.externalID || " "
88
+ data << "}"
89
+ end
90
+ def to_json_for_status_client
91
+ # source: 'CRAIG', externalID: 3434399120
92
+ data = "source:'#{CGI.escape self.source}', "
93
+ data << "externalID:#{CGI.escape self.externalID}"
94
+ data
95
+ end
96
+
97
+ end
@@ -0,0 +1,8 @@
1
+ # Class PostingHistory represents structure of history
2
+ #
3
+ # history = PostingHistory.new
4
+ # history.history # => String
5
+ #
6
+ class PostingHistory < Struct.new(:history)
7
+ #include HashedInitializer
8
+ end
@@ -0,0 +1,27 @@
1
+ # Class Source represents structure of source
2
+ #
3
+ # source = Source.new
4
+ # source.name # => String
5
+ # source.code # => String
6
+ # source.logo_url # => String
7
+ # source.logo_sm_url # => String
8
+ # source.hidden # => Boolean
9
+ #
10
+ # source.from_array(array) # => Array of Source objects
11
+ #
12
+ class Source < Struct.new(:name, :code, :logo_url, :logo_sm_url, :hidden)
13
+
14
+
15
+ # Method +from_array+ returns array of sources(create from json).
16
+ # Takes value of array objects as json parameter array.
17
+ #
18
+ # Example:
19
+ #
20
+ # Source.from_array([...array of JSON objects...]) # => Array of Source
21
+ #
22
+ def self.from_array(array)
23
+ array.collect do |element|
24
+ Source.new(element)
25
+ end
26
+ end
27
+ end
data/lib/struct.rb ADDED
@@ -0,0 +1,16 @@
1
+ class Struct
2
+
3
+ def self.from_hash(h)
4
+ o = new
5
+ h.each do |m, v|
6
+ o[m.to_sym] = v
7
+ end
8
+ o
9
+ end
10
+
11
+ def self.from_array(a)
12
+ a.collect do |b|
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'cgi'
3
+ require 'supermodel'
4
+ require 'active_support'
5
+ require 'curb'
6
+ require 'struct'
7
+
8
+ require 'client/client'
9
+ require 'client/search_client'
10
+ require 'client/posting_client'
11
+ require 'client/geocoder_client'
12
+ require 'client/reference_client'
13
+ require 'client/search_client'
14
+ require 'client/status_client'
15
+
16
+
17
+ require 'dto/geocoder/geocoder_request'
18
+ require 'dto/geocoder/geocoder_response'
19
+
20
+ require 'dto/posting/create_response'
21
+ require 'dto/posting/delete_response'
22
+ require 'dto/posting/update_response'
23
+ require 'dto/posting/exists_response'
24
+
25
+ require 'dto/status/get_status_response'
26
+ require 'dto/status/status_update_request'
27
+
28
+ require 'dto/search/best_match_response'
29
+ require 'dto/search/count_response'
30
+ require 'dto/search/range_response'
31
+ require 'dto/search/range_request'
32
+ require 'dto/search/search_response'
33
+ require 'dto/search/search_request'
34
+ require 'dto/search/summary_response'
35
+ require 'dto/search/summary_request'
36
+
37
+ require 'models/category'
38
+ require 'models/location'
39
+ require 'models/message'
40
+ require 'models/posting'
41
+ require 'models/posting_history'
42
+ require 'models/source'
43
+ require 'models/annotations/annotation'
44
+ require 'models/annotations/annotation_option'
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Client do
4
+ before(:each) do
5
+ @client = Client.new
6
+ end
7
+
8
+ it "should decode data" do
9
+ data = mock "[]"
10
+ ActiveSupport::JSON.should_receive(:decode).with(data)
11
+ @client.send(:decode,data)
12
+ end
13
+
14
+ it "should desc" do
15
+ # TODO
16
+ end
17
+ end
18
+
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe GeocoderClient do
4
+ before(:each) do
5
+ @geocoder_client = GeocoderClient.new
6
+ end
7
+
8
+ it "should send GET request and create GeocoderResponse from result" do
9
+ geocoder_request = mock "geocoder_request"
10
+ geocoder_request.should_receive(:to_params)
11
+ array = mock "array"
12
+ geocoder_response = mock "geocoder_response"
13
+ GeocoderResponse.should_receive(:from_array).and_return array
14
+
15
+ @geocoder_client.geocode(geocoder_request).should == array
16
+ end
17
+ end
18
+