threetaps-client 1.0.2 → 1.0.3

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 CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -81,8 +81,9 @@ class PostingClient < Client
81
81
  # Returns information on the existence of postings.
82
82
  #
83
83
  def exists_posting(posting)
84
- params = "ids=#{posting}"
84
+ params = "ids=[#{posting.to_json_for_status}]"
85
85
  response = execute_post("/posting/exists", params)
86
- ExistsResponse.from_array(decode(response))
86
+ p decode(response)[0]
87
+ ExistsResponse.new(decode(response)[0])
87
88
  end
88
89
  end
@@ -76,7 +76,7 @@ class SearchClient < Client
76
76
  #
77
77
  def best_match(keywords)
78
78
  response = execute_get("/search/best-match", "keywords=#{keywords}")
79
- BestMatchResponse.from_hash(decode(response))
79
+ BestMatchResponse.new(decode(response))
80
80
  end
81
81
 
82
82
  end
@@ -54,7 +54,7 @@ class StatusClient < Client
54
54
  data = "["
55
55
  data << postings.collect{|posting| "{#{posting.to_json_for_status_client}}"}.join(',')
56
56
  data << "]"
57
- params = "ids=#{data}"
57
+ params = "postings=#{data}"
58
58
  response = execute_post("status/get", params)
59
59
  GetStatusResponse.from_array(decode(response))
60
60
  end
@@ -7,10 +7,10 @@
7
7
  # response = ExistsResponse.from_hash("success" => "true")
8
8
  # response.success # => true
9
9
  #
10
- class ExistsResponse
11
- attr_accessor :exists, :postKey, :error
12
-
13
- def self.from_array(json)
14
- json
10
+ class ExistsResponse < Struct.new(:indexed, :postKey, :exists, :failures)
11
+ def initialize(hash = {})
12
+ hash.each do |key, value|
13
+ self.send("#{key}=".to_sym, value )
14
+ end
15
15
  end
16
16
  end
@@ -12,9 +12,14 @@
12
12
  # response.numResults # => 20
13
13
  # response.num_results # => 20
14
14
  #
15
- class BestMatchResponse < Struct.new(:category, :numResults) do
15
+ class BestMatchResponse < Struct.new(:category, :numResults, :error) do
16
16
  def num_results
17
17
  numResults
18
18
  end
19
19
  end
20
+ def initialize(hash = {})
21
+ hash.each do |key, value|
22
+ self.send("#{key}=".to_sym, value )
23
+ end
24
+ end
20
25
  end
@@ -33,10 +33,10 @@
33
33
  # posting.to_json_for_status # => Array of JSON objects
34
34
  class Posting < SuperModel::Base
35
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
36
+ :longitude, :latitude, :language, :price, :currency, :images,
37
+ :externalURL, :externalID, :accountName, :accountID, :clickCount,
38
+ :timestamp, :expiration, :indexed, :trustedAnnotations,
39
+ :annotations, :errors, :status, :history
40
40
 
41
41
  def initialize(*params)
42
42
  super(*params)
@@ -46,10 +46,14 @@ class Posting < SuperModel::Base
46
46
  end
47
47
 
48
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/,"+")}'"
49
+ posting = "{"+'source:'+"'#{self.source}'" + ',category:' + "'#{self.category}'" + ',location:' + "'#{self.location}'" + ',heading:' + "'#{CGI.escape self.heading.to_json}'"
50
+ if self.timestamp
51
+ posting << ",timestamp: '#{(self.timestamp.utc.to_s(:db)).gsub(/\s/,"+")}'"
52
+ else
53
+ posting << ",timestamp: '#{(Time.now.utc.to_s(:db)).gsub(/\s/,"+")}'"
54
+ end
51
55
  posting << ',images:' + "[#{images.collect{ |image| "'#{image}'"}.join(',')}]"
52
- posting << ',body:' + "'#{CGI.escape self.body.gsub(/\n/," ")}'" unless self.body.blank?
56
+ posting << ',body:' + "'#{CGI.escape self.body.to_json}'" unless self.body.blank?
53
57
  posting << ',price:' + "'#{self.price}'"
54
58
  posting << ',currency:' + "'#{self.currency}'"
55
59
  posting << ',accountName:' + "'#{self.accountName}'"
@@ -66,12 +70,12 @@ class Posting < SuperModel::Base
66
70
 
67
71
  def to_json_for_update
68
72
  data = "['#{self.postKey}',"
69
- data << "{heading:"+ "'#{CGI.escape self.heading}'" unless self.heading.blank?
73
+ data << "{heading:"+ "'#{CGI.escape self.heading.to_json}'" unless self.heading.blank?
70
74
  data << ",images:" + "[#{images.collect{ |image| "'#{image}'"}.join(',')}]"
71
75
  data << ",source:'#{self.source}'" unless self.source.blank?
72
76
  data << ",category:'#{self.category}'" unless self.category.blank?
73
77
  data << ",location:'#{self.location}'" unless self.location.blank?
74
- data << ",body:" + "'#{CGI.escape self.body.gsub(/\n/," ")}'" unless self.body.blank?
78
+ data << ",body:" + "'#{CGI.escape self.body.to_json}'" unless self.body.blank?
75
79
  data << ',price:' + "'#{self.price}'"
76
80
  data << ',currency:' + "'#{self.currency}'"
77
81
  data << ',accountName:' + "'#{self.accountName}'"
@@ -30,7 +30,9 @@ describe PostingClient do
30
30
 
31
31
  it "should return boolean value" do
32
32
  stub_post_and_json_decode
33
- @posting_client.exists_posting(mock("")).should be_true
33
+ ExistsResponse.stub!(:new).and_return mock("ExistsResponse", :exists => true)
34
+ ExistsResponse.should_receive(:new).with(nil)
35
+ @posting_client.exists_posting(mock("Posting", :to_json_for_status=>"")).exists.should be_true
34
36
  end
35
37
  end
36
38
 
@@ -44,7 +44,8 @@ describe SearchClient do
44
44
  it "should send GET request and create BestMatchResponse from result" do
45
45
  keywords = ""
46
46
  bestmatch_response = mock "bestmatch_response"
47
- BestMatchResponse.should_receive(:from_hash).and_return bestmatch_response
47
+ stub_get_and_json_decode
48
+ BestMatchResponse.stub!(:new).and_return bestmatch_response
48
49
 
49
50
  @search_client.best_match(keywords).should == bestmatch_response
50
51
  end
@@ -7,6 +7,8 @@ class TestPostingClient < Test::Unit::TestCase
7
7
  posting = Posting.new(
8
8
  :source => "3TAPS",
9
9
  :heading => "Svitla posting",
10
+ :location => "ZZZ",
11
+ :category => "ZZZZ",
10
12
  :timestamp => Time.now
11
13
  )
12
14
  response = client.create_posting(posting)
@@ -14,29 +16,33 @@ class TestPostingClient < Test::Unit::TestCase
14
16
  assert_equal CreateResponse, response.first.class
15
17
  assert_nil response.first.error
16
18
  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)
19
+ p posting_key
20
+ # posting.heading = "Svitla posting +++#{rand(100)}+++"
21
+ # posting.postKey = posting_key
22
+ # posting.body = "posting"
23
+ # # sleep(50)
24
+ # response = client.update_posting(posting)
25
+ # p response
26
+ # assert_equal true, response.success
27
+ #
28
+ # keys << posting_key
29
+ #
30
+ # posting = Posting.new(
31
+ # :source => "3TAPS",
32
+ # :heading => "Svitla posting",
33
+ # :location => "ZZZ",
34
+ # :category => "ZZZZ",
35
+ # :timestamp => Time.now
36
+ # )
37
+ # response = client.create_posting(posting)
38
+ # assert_equal Array, response.class
39
+ # assert_equal CreateResponse, response.first.class
40
+ # assert_nil response.first.error
41
+ # posting_key = response.first.post_key
42
+ # keys << posting_key
43
+ p "waiting while indexed by server"
44
+ sleep(10)
45
+ response = client.delete_posting(posting_key)
40
46
  assert_equal DeleteResponse, response.class
41
47
  assert_equal true, response.success
42
48
  end
@@ -46,18 +52,23 @@ class TestPostingClient < Test::Unit::TestCase
46
52
  posting1 = Posting.new(
47
53
  :source => "3TAPS",
48
54
  :heading => "Svitla posting1",
55
+ :location => "ZZZ",
56
+ :category => "ZZZZ",
49
57
  :timestamp => Time.now
50
58
  )
51
59
  posting2 = Posting.new(
52
60
  :source => "3TAPS",
53
61
  :heading => "Svitla posting2",
54
- :timestamp => Time.now
62
+ :location => "ZZZ",
63
+ :category => "ZZZZ"
55
64
  )
56
65
  response = client.create_posting([posting1, posting2])
66
+ p response
57
67
  assert_equal Array, response.class
58
68
  assert_equal CreateResponse, response.first.class
59
69
  assert_nil response.first.error
60
-
70
+ p "waiting while indexed by server"
71
+ sleep(15)
61
72
  posting_key = response[0].post_key
62
73
  posting1.postKey = posting_key
63
74
  posting_key = response[1].post_key
@@ -75,9 +86,9 @@ class TestPostingClient < Test::Unit::TestCase
75
86
 
76
87
  should "test posting retrieval" do
77
88
  client = PostingClient.new
78
- posting = client.get_posting("BF87BFW")
89
+ posting = client.get_posting("BLQ7YJD")
79
90
  assert_equal Posting, posting.class
80
- assert_equal "BF87BFW", posting.postKey
91
+ assert_equal "BLQ7YJD", posting.postKey
81
92
  end
82
93
 
83
94
  should "test posting deletion" do
@@ -23,7 +23,7 @@ class TestSearchClient < Test::Unit::TestCase
23
23
  search_response = client.search(search_request)
24
24
  assert_equal SearchResponse, search_response.class
25
25
  assert_equal Array, search_response.results.class
26
- assert_equal Posting, search_response.results.first.class
26
+ assert_equal Hash, search_response.results.first.class
27
27
  end
28
28
 
29
29
  should "get the count request result" do
@@ -47,9 +47,9 @@ class TestSearchClient < Test::Unit::TestCase
47
47
  end
48
48
 
49
49
  should "get the best match result" do
50
- search_keywords = "iPad,Apple,iPhone"
50
+ search_keywords = "iPad Apple iPhone"
51
51
  client = SearchClient.new
52
- best_match_response = client.best_match(search_keywords)
52
+ best_match_response = client.best_match(CGI.escape search_keywords)
53
53
  assert_equal BestMatchResponse, best_match_response.class
54
54
  assert_equal 'SELE', best_match_response.category
55
55
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 2
9
- version: 1.0.2
8
+ - 3
9
+ version: 1.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - 3taps.com
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-06 00:00:00 +03:00
17
+ date: 2011-04-10 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -220,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
220
  requirements:
221
221
  - - ">="
222
222
  - !ruby/object:Gem::Version
223
- hash: -307507889
223
+ hash: -228372899
224
224
  segments:
225
225
  - 0
226
226
  version: "0"