gun_broker 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 657189493f5cfb8faf699f3100fe60bd18190012
4
- data.tar.gz: c1ccb2b44db024453638d5fa70204da06ce128fb
3
+ metadata.gz: 337ab5362759c2da234b08bba92463def82f3032
4
+ data.tar.gz: bc0f1401ca5ea0acd8761df09ac592c5421d8037
5
5
  SHA512:
6
- metadata.gz: 72ce3a15f96a354f2e93f378a6639b011386418123716304a6be15b839b54a5581a67d3f9bc92566126034166047dd485dc50c5616aea717df42b60c217462e6
7
- data.tar.gz: 4c85034d8ebf42def28fb7aa2316326c2fb02f1eea25092ac52e5b85ab05abdc4fe6ff8b1db20cd8910d5de83f87193e3281b394bea7e4ddd453636d9c1d0171
6
+ metadata.gz: 85131d4627c24cecff1b878ccbcfc62882de9d503d563ec19df6a296ff1e278516dd2d55ee4319fe8522584bd4f5572b988e2aa57f1127c49169ec2816e8d7fc
7
+ data.tar.gz: 0fad394047ced20e7dd520dbc84e26c0ebcb2d5880022c9b3efd8d9972eeb6dad4812ea7505fdfe61c67b83e7d85b8db0e2ac8fa59dd0229d5d383d3163c867f
@@ -3,6 +3,7 @@ require 'gun_broker/version'
3
3
  require 'gun_broker/api'
4
4
  require 'gun_broker/category'
5
5
  require 'gun_broker/error'
6
+ require 'gun_broker/feedback'
6
7
  require 'gun_broker/item'
7
8
  require 'gun_broker/response'
8
9
  require 'gun_broker/user'
@@ -5,10 +5,10 @@ module GunBroker
5
5
  # The top-level category ID.
6
6
  ROOT_CATEGORY_ID = 0
7
7
 
8
- # @param parent [Integer, String] (optional) Return all subcategories of the given parent Category ID; defaults to the root (top-level) categories.
8
+ # @param parent_id [Integer, String] (optional) Return all subcategories of the given parent Category ID; defaults to the root (top-level) categories.
9
9
  # @return [Array<Category>] An array of GunBroker::Category instances.
10
- def self.all(parent = ROOT_CATEGORY_ID)
11
- response = GunBroker::API.get('/Categories', { 'ParentCategoryID' => parent })
10
+ def self.all(parent_id = ROOT_CATEGORY_ID)
11
+ response = GunBroker::API.get('/Categories', { 'ParentCategoryID' => parent_id })
12
12
  response['results'].map { |attrs| new(attrs) }
13
13
  end
14
14
 
@@ -0,0 +1,31 @@
1
+ module GunBroker
2
+ # Handles feedback about and by a {User}.
3
+ class Feedback
4
+
5
+ # @param user_id [Integer, String] Return feedback by this User's ID.
6
+ # @return [Array<Feedback>] An array of the User's feedback.
7
+ def self.all(user_id)
8
+ response = GunBroker::API.get("/Feedback/#{user_id}")
9
+ response['results'].map { |attrs| new(attrs) }
10
+ end
11
+
12
+ # @param user_id [Integer, String] Get feedback summary about the `user_id`.
13
+ # @return [GunBroker::Response]
14
+ def self.summary(user_id)
15
+ GunBroker::API.get("/Feedback/Summary/#{user_id}")
16
+ end
17
+
18
+ # @param attrs [Hash] The JSON attributes from the API response.
19
+ def initialize(attrs = {})
20
+ @attrs = attrs
21
+ end
22
+
23
+ # @return [GunBroker::Item] The Item this feedback is about.
24
+ #
25
+ # See also: {GunBroker::Item.find}
26
+ def item
27
+ GunBroker::Item.find(@attrs['itemID'])
28
+ end
29
+
30
+ end
31
+ end
@@ -6,6 +6,7 @@ module GunBroker
6
6
 
7
7
  include GunBroker::Item::Constants
8
8
 
9
+ # TODO: Refactor this, #attributes, and #[] into a module.
9
10
  # @return [Hash] Attributes parsed from the JSON response.
10
11
  attr_reader :attrs
11
12
 
@@ -1,3 +1,3 @@
1
1
  module GunBroker
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
@@ -0,0 +1,27 @@
1
+ {
2
+ "isUserRegistered": true,
3
+ "links": [
4
+ {
5
+ "href": "https://api.gunbroker.com/v1/feedback/123",
6
+ "rel": "details",
7
+ "title": "test-user",
8
+ "verb": "GET"
9
+ }
10
+ ],
11
+ "negativeFeedback120Days": 0,
12
+ "negativeFeedback30Days": 0,
13
+ "negativeFeedback60Days": 0,
14
+ "negativeFeedback90Days": 0,
15
+ "negativeFeedbackPoints": 1,
16
+ "neutralFeedbackPoints": 0,
17
+ "positiveFeedbackPercentage": 50.0,
18
+ "positiveFeedbackPoints": 1,
19
+ "totalFeedbackPoints": 2,
20
+ "user": {
21
+ "feedbackRating": "C(2)",
22
+ "isVerified": true,
23
+ "isffl": false,
24
+ "userID": 123,
25
+ "username": "tet-user"
26
+ }
27
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "count": 2,
3
+ "links": [],
4
+ "pageIndex": 1,
5
+ "pageSize": 25,
6
+ "results": [
7
+ {
8
+ "buyerSellerStatus": "S",
9
+ "comment": "Never received item. Seller would not respond to emails or phone message. Money refunded 11 days after payment was sent only after filing a dispute with PayPal. Don't recommend dealing w/ this person.",
10
+ "date": "2014-08-22T20:57:19Z",
11
+ "followUp": null,
12
+ "followUpDate": null,
13
+ "fromUser": {
14
+ "feedbackRating": "A+(13)",
15
+ "isVerified": true,
16
+ "isffl": false,
17
+ "userID": 12345,
18
+ "username": "joe-user"
19
+ },
20
+ "isRegistered": true,
21
+ "itemID": 123,
22
+ "links": [
23
+ {
24
+ "href": "https://api.gunbroker.com/v1/items/123",
25
+ "rel": "item",
26
+ "title": "123",
27
+ "verb": "GET"
28
+ },
29
+ {
30
+ "href": "https://api.gunbroker.com/v1/feedback/12345",
31
+ "rel": "fromuserfeedback",
32
+ "title": "joe-user",
33
+ "verb": "GET"
34
+ }
35
+ ],
36
+ "ratingLetter": "F",
37
+ "ratingScore": 0.0,
38
+ "reply": null,
39
+ "replyDate": null
40
+ },
41
+ {
42
+ "buyerSellerStatus": "S",
43
+ "comment": "Excellent transaction. Good communication. A+",
44
+ "date": "2014-07-09T19:46:57Z",
45
+ "followUp": null,
46
+ "followUpDate": null,
47
+ "fromUser": {
48
+ "feedbackRating": "A+(94)",
49
+ "isVerified": true,
50
+ "isffl": false,
51
+ "userID": 9876,
52
+ "username": "other-user"
53
+ },
54
+ "isRegistered": true,
55
+ "itemID": 530,
56
+ "links": [
57
+ {
58
+ "href": "https://api.gunbroker.com/v1/items/530",
59
+ "rel": "item",
60
+ "title": "414806299",
61
+ "verb": "GET"
62
+ },
63
+ {
64
+ "href": "https://api.gunbroker.com/v1/feedback/9876",
65
+ "rel": "fromuserfeedback",
66
+ "title": "other-user",
67
+ "verb": "GET"
68
+ }
69
+ ],
70
+ "ratingLetter": "A+",
71
+ "ratingScore": 5.0,
72
+ "reply": null,
73
+ "replyDate": null
74
+ }
75
+ ]
76
+ }
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe GunBroker::Feedback do
4
+
5
+ let(:attrs) { JSON.parse(response_fixture('feedback')) }
6
+
7
+ let(:user_id) { 123 }
8
+ let(:endpoint) { [GunBroker::API::GUNBROKER_API, "/Feedback/#{user_id}"].join }
9
+ let(:summary_endpoint) { [GunBroker::API::GUNBROKER_API, "/Feedback/Summary/#{user_id}"].join }
10
+
11
+ context '.all' do
12
+ it 'returns an array of the user feedback' do
13
+ stub_request(:get, endpoint)
14
+ .with(headers: headers)
15
+ .to_return(body: response_fixture('feedback'))
16
+
17
+ feedback = GunBroker::Feedback.all(user_id)
18
+ expect(feedback.first).to be_a(GunBroker::Feedback)
19
+ end
20
+ end
21
+
22
+ context '.summary' do
23
+ it 'returns an array of the user feedback' do
24
+ stub_request(:get, summary_endpoint)
25
+ .with(headers: headers)
26
+ .to_return(body: response_fixture('feedback-summary'))
27
+
28
+ summary = GunBroker::Feedback.summary(user_id)
29
+ expect(summary).to be_a(GunBroker::Response)
30
+ end
31
+ end
32
+
33
+ context '#item' do
34
+ let(:item_id) { attrs['results'].first['itemID'] }
35
+ let(:item_endpoint) { [GunBroker::API::GUNBROKER_API, "/Items/#{item_id}"].join }
36
+
37
+ it 'should have an Item' do
38
+ stub_request(:get, endpoint)
39
+ .with(headers: headers)
40
+ .to_return(body: response_fixture('feedback'))
41
+
42
+ stub_request(:get, item_endpoint)
43
+ .with(headers: headers)
44
+ .to_return(body: response_fixture('item'))
45
+
46
+ all_feedback = GunBroker::Feedback.all(user_id)
47
+ feedback = all_feedback.first
48
+
49
+ expect(feedback.item).to be_a(GunBroker::Item)
50
+ end
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gun_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell
@@ -101,6 +101,7 @@ files:
101
101
  - lib/gun_broker/api.rb
102
102
  - lib/gun_broker/category.rb
103
103
  - lib/gun_broker/error.rb
104
+ - lib/gun_broker/feedback.rb
104
105
  - lib/gun_broker/item.rb
105
106
  - lib/gun_broker/item/constants.rb
106
107
  - lib/gun_broker/response.rb
@@ -114,6 +115,8 @@ files:
114
115
  - spec/fixtures/contact_info.json
115
116
  - spec/fixtures/deauthenticate.json
116
117
  - spec/fixtures/empty.json
118
+ - spec/fixtures/feedback-summary.json
119
+ - spec/fixtures/feedback.json
117
120
  - spec/fixtures/item.json
118
121
  - spec/fixtures/items.json
119
122
  - spec/fixtures/not_authorized.json
@@ -121,6 +124,7 @@ files:
121
124
  - spec/fixtures/time.json
122
125
  - spec/gun_broker/api_spec.rb
123
126
  - spec/gun_broker/category_spec.rb
127
+ - spec/gun_broker/feedback_spec.rb
124
128
  - spec/gun_broker/item/constants_spec.rb
125
129
  - spec/gun_broker/item_spec.rb
126
130
  - spec/gun_broker/token_header_spec.rb
@@ -161,6 +165,8 @@ test_files:
161
165
  - spec/fixtures/contact_info.json
162
166
  - spec/fixtures/deauthenticate.json
163
167
  - spec/fixtures/empty.json
168
+ - spec/fixtures/feedback-summary.json
169
+ - spec/fixtures/feedback.json
164
170
  - spec/fixtures/item.json
165
171
  - spec/fixtures/items.json
166
172
  - spec/fixtures/not_authorized.json
@@ -168,6 +174,7 @@ test_files:
168
174
  - spec/fixtures/time.json
169
175
  - spec/gun_broker/api_spec.rb
170
176
  - spec/gun_broker/category_spec.rb
177
+ - spec/gun_broker/feedback_spec.rb
171
178
  - spec/gun_broker/item/constants_spec.rb
172
179
  - spec/gun_broker/item_spec.rb
173
180
  - spec/gun_broker/token_header_spec.rb