Skip to content

Commit 099664d

Browse files
Merge pull request #7 from gfish/handle-customer-id-in-the-request-url
Include customer ID in the API request URL
2 parents fe8398f + a2cb8eb commit 099664d

7 files changed

Lines changed: 22 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 2.0.0 - 2020-10-29
2+
3+
* A customer ID is needed to create a client instance
4+
* Always include the Customer ID in the API request URL
5+
* Bump webmock to properly handle Ruby 2.4+
6+
17
### 1.1.6 - 2017-03-15
28

39
* Now by default, during creation event, we support using redirect urls

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ end
8080
Initialize client to pass it as a dependency to `Event` instance.
8181

8282
``` ruby
83-
client = QueueIt::Api::Client.new(api_key: "SECRET_API_KEY")
83+
client = QueueIt::Api::Client.new("YOUR_CUSTOMER_ID", api_key: "SECRET_API_KEY")
8484
```
8585

8686
#### Event

lib/queue_it/api/client.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ module QueueIt
88
module Api
99
class Client
1010
JSON_FORMAT = "application/json".freeze
11-
ENDPOINT_URL = URI("https://api2.queue-it.net/2_0/event").freeze
1211

13-
def initialize(api_key: nil, debug: false)
12+
def initialize(customer_id, api_key: nil, debug: false)
13+
self.customer_id = customer_id
1414
self.api_key = api_key
1515
self.debug = debug
16+
self.endpoint = URI("https://#{customer_id}.api2.queue-it.net/2_0/event")
1617
end
1718

1819
def put(path, body)
@@ -21,11 +22,11 @@ def put(path, body)
2122

2223
private
2324

24-
attr_accessor :api_key, :debug
25+
attr_accessor :api_key, :customer_id, :debug, :endpoint
2526

2627
def options
2728
{
28-
url: ENDPOINT_URL.dup,
29+
url: endpoint.dup,
2930
headers: {
3031
accept: JSON_FORMAT,
3132
content_type: JSON_FORMAT,

lib/queue_it/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module QueueIt
2-
VERSION = "1.1.8"
2+
VERSION = "2.0.0"
33
end

queue_it.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
2424

2525
spec.add_development_dependency "bundler", "~> 1.3"
2626
spec.add_development_dependency "rspec", "~> 3.2"
27-
spec.add_development_dependency "webmock", "~> 1.21"
27+
spec.add_development_dependency "webmock", "~> 3.3"
2828
end

spec/queue_it/api/client_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module QueueIt
66
module Api
77
describe Client do
8-
subject(:client) { described_class.new(api_key: "SECURE_KEY") }
8+
subject(:client) { Client.new("customerid", api_key: "SECURE_KEY") }
99

1010
specify "PUT data under given endpoint & path in JSON format" do
1111
request_hash = { "Request" => true }
@@ -71,7 +71,7 @@ module Api
7171
end
7272

7373
specify "debugging mode puts to STDOUT" do
74-
client = Client.new(api_key: "SECURE_KEY", debug: true)
74+
client = Client.new("customerid", api_key: "SECURE_KEY", debug: true)
7575

7676
request_hash = { "Request" => true }
7777

@@ -83,7 +83,7 @@ module Api
8383
private
8484

8585
def endpoint_url
86-
Client::ENDPOINT_URL.to_s + "/fancy_event"
86+
"https://customerid.api2.queue-it.net/2_0/event/fancy_event"
8787
end
8888

8989
def stub_request_factory(method: :put, status: 200, request_body: "{}", response_body: "{}", content_type: "application/json")

spec/queue_it/api/event_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ module Api
108108
end
109109

110110
specify "Request hits proper endpoint" do
111-
client = Client.new(api_key: "SECURE_KEY")
111+
client = Client.new("customerid", api_key: "SECURE_KEY")
112112
event_adapter = Event.new(client)
113113

114114
body = JSON.generate(valid_create_body)
115115

116-
stub = stub_request(:put, "https://api2.queue-it.net/2_0/event/fancyevent")
116+
stub = stub_request(:put, "https://customerid.api2.queue-it.net/2_0/event/fancyevent")
117117
.with(body: body, headers: headers)
118118

119119
event_adapter.create_or_update(event_id: event_id,
@@ -165,13 +165,13 @@ module Api
165165
end
166166

167167
context "#set_speed" do
168-
let(:client) { Client.new(api_key: "SECURE_KEY") }
168+
let(:client) { Client.new("customerid", api_key: "SECURE_KEY") }
169169
let(:max_redirects_per_minute) { 15 }
170170

171171
specify "Proper speed value is set" do
172172
body = { "MaxRedirectsPerMinute" => "15" }
173173

174-
stub = stub_request(:put, "https://api2.queue-it.net/2_0/event/fancyevent/queue/speed")
174+
stub = stub_request(:put, "https://customerid.api2.queue-it.net/2_0/event/fancyevent/queue/speed")
175175
.with(body: body, headers: headers)
176176

177177
event_adapter.set_speed(event_id: event_id, max_redirects_per_minute: max_redirects_per_minute)
@@ -182,7 +182,7 @@ module Api
182182
specify "Speed must be greater than 5 so we send at least 5" do
183183
expected_body = { "MaxRedirectsPerMinute" => "5" }
184184

185-
stub = stub_request(:put, "https://api2.queue-it.net/2_0/event/fancyevent/queue/speed")
185+
stub = stub_request(:put, "https://customerid.api2.queue-it.net/2_0/event/fancyevent/queue/speed")
186186
.with(body: expected_body, headers: headers)
187187

188188
event_adapter.set_speed(event_id: event_id, max_redirects_per_minute: 1)

0 commit comments

Comments
 (0)