stretchr 1.2.3 → 1.3.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.
- checksums.yaml +4 -4
- data/lib/stretchr/client.rb +2 -1
- data/lib/stretchr/request.rb +13 -3
- data/lib/stretchr/transporters/json_transporter.rb +7 -1
- data/test/test_client.rb +5 -0
- data/test/test_request.rb +11 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e5b8e89dbf9d5bf8df7927c8f871b03af916b64
|
|
4
|
+
data.tar.gz: cf85a4a1530398710152a48e13b209b5bc6423bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e16c6f1fe0b43049f6c0b0bfb0bb7152fb63fc6bd5951c5ec004132f00151bb085b36b28450980835bf29f85dc0557a93cbc1163deb48d01b7b90bb41dfd383b
|
|
7
|
+
data.tar.gz: b497813de26adfe3fc462d6786f6ab72b50ac3e746fa1097adfd520d5ea61ce4309a3a249b104c0ea360946433795f889838d88c6cd76ed71177954d11640808
|
data/lib/stretchr/client.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Stretchr
|
|
2
2
|
class Client
|
|
3
|
-
attr_accessor :transporter, :api_version, :project, :key, :hostname
|
|
3
|
+
attr_accessor :transporter, :api_version, :project, :key, :hostname, :account
|
|
4
4
|
# Initializes a new stretchr client
|
|
5
5
|
# This is the main entrypoint into working with stretchr
|
|
6
6
|
#
|
|
@@ -15,6 +15,7 @@ module Stretchr
|
|
|
15
15
|
self.project = options[:project]
|
|
16
16
|
self.key = options[:key]
|
|
17
17
|
self.hostname = options[:hostname] || Stretchr.config["hostname"]
|
|
18
|
+
self.account = options[:account]
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# Catches everything you can throw at client and passes it on to a new request object
|
data/lib/stretchr/request.rb
CHANGED
|
@@ -32,7 +32,7 @@ module Stretchr
|
|
|
32
32
|
|
|
33
33
|
# Builds a URI object
|
|
34
34
|
def to_uri
|
|
35
|
-
URI::
|
|
35
|
+
URI::HTTPS.build(host: merge_host, path: merge_path, query: merge_query)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Set params for the url
|
|
@@ -171,11 +171,21 @@ module Stretchr
|
|
|
171
171
|
return self
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
+
# Set the path directly without having to go through it piece by piece
|
|
175
|
+
#
|
|
176
|
+
# ==== Examples
|
|
177
|
+
# r= Stretchr::Request.new
|
|
178
|
+
# r.at("people/1/cars").path #=> "people/1/cars"
|
|
179
|
+
def at(path)
|
|
180
|
+
@path_elements += path.split("/")
|
|
181
|
+
return self
|
|
182
|
+
end
|
|
183
|
+
|
|
174
184
|
private
|
|
175
185
|
|
|
176
186
|
# Merges the path from the @path_elements
|
|
177
187
|
def merge_path
|
|
178
|
-
"/api/#{client.api_version}/#{@path_elements.join('/')}"
|
|
188
|
+
"/api/#{client.api_version}/#{client.project}/#{@path_elements.join('/')}"
|
|
179
189
|
end
|
|
180
190
|
|
|
181
191
|
# Merges query params and filter params
|
|
@@ -188,7 +198,7 @@ module Stretchr
|
|
|
188
198
|
|
|
189
199
|
# Generate the host from the hostname and project
|
|
190
200
|
def merge_host
|
|
191
|
-
"#{client.
|
|
201
|
+
"#{client.account}.#{client.hostname}"
|
|
192
202
|
end
|
|
193
203
|
end
|
|
194
204
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
require "uri" if !defined? URI
|
|
2
2
|
require "net/http" if !defined? Net
|
|
3
|
+
require "json" if !defined? JSON
|
|
4
|
+
|
|
3
5
|
module Stretchr
|
|
4
6
|
class JSONTransporter
|
|
5
7
|
# Perform the request against stretchr
|
|
@@ -8,7 +10,11 @@ module Stretchr
|
|
|
8
10
|
# Expects: {uri: URIOBJECT, body: "body", method: "PUT/PATCH/POST/DELETE/GET", client: stretchr client}
|
|
9
11
|
def make_request(request)
|
|
10
12
|
response = nil
|
|
11
|
-
|
|
13
|
+
|
|
14
|
+
#convert to a json string unless the user already did it...
|
|
15
|
+
request[:body] = request[:body].to_json unless request[:body].is_a?(String)
|
|
16
|
+
|
|
17
|
+
Net::HTTP.start(request[:uri].host, request[:uri].port, {use_ssl: true}) do |http|
|
|
12
18
|
http_request = generate_request(request)
|
|
13
19
|
response = http.request http_request # Net::HTTPResponse object
|
|
14
20
|
end
|
data/test/test_client.rb
CHANGED
|
@@ -31,6 +31,11 @@ describe "Client" do
|
|
|
31
31
|
assert_equal stretchr, r.client, "Should have passed the client into the request"
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
it "Shoudl let me specify the account" do
|
|
35
|
+
stretchr = Stretchr::Client.new({account: "ryan"})
|
|
36
|
+
assert_equal "ryan", stretchr.account, "Should have let me set the account"
|
|
37
|
+
end
|
|
38
|
+
|
|
34
39
|
it "Should have a default api_version" do
|
|
35
40
|
stretchr = Stretchr::Client.new
|
|
36
41
|
assert stretchr.api_version, "Should have set a default api version"
|
data/test/test_request.rb
CHANGED
|
@@ -8,9 +8,9 @@ describe "Request Object" do
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it "Should know how to build a complete url including path" do
|
|
11
|
-
c = Stretchr::Client.new({project: "project", api_version: "v1.1"})
|
|
11
|
+
c = Stretchr::Client.new({account: "account", project: "project", api_version: "v1.1"})
|
|
12
12
|
r = Stretchr::Request.new({client: c})
|
|
13
|
-
assert_equal "
|
|
13
|
+
assert_equal "https://account.stretchr.com/api/v1.1/project/people/1/cars", r.people(1).cars.to_url, "Should have built the url properly"
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "Should let you pass in params" do
|
|
@@ -108,11 +108,11 @@ describe "Request Object" do
|
|
|
108
108
|
|
|
109
109
|
it "should pass the correct uri to the transporter" do
|
|
110
110
|
t = Stretchr::TestTransporter.new
|
|
111
|
-
c = Stretchr::Client.new({project: "project", api_version: "v1.1", transporter: t})
|
|
111
|
+
c = Stretchr::Client.new({account: "account", project: "project", api_version: "v1.1", transporter: t})
|
|
112
112
|
r = Stretchr::Request.new({client: c})
|
|
113
113
|
r.people.get
|
|
114
|
-
assert_equal "
|
|
115
|
-
assert_equal "
|
|
114
|
+
assert_equal "https://account.stretchr.com/api/v1.1/project/people", r.to_url, "Should have saved the right url in the request"
|
|
115
|
+
assert_equal "https://account.stretchr.com/api/v1.1/project/people", t.requests.first[:uri].to_s, "Should have created the right URL and sent it to the transporter"
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "Should know how to handle paging" do
|
|
@@ -181,4 +181,10 @@ describe "Request Object" do
|
|
|
181
181
|
r.people.delete
|
|
182
182
|
assert_equal :delete, t.requests[1][:method], "Should have performed a delete request"
|
|
183
183
|
end
|
|
184
|
+
|
|
185
|
+
it "Should let me set the path manually" do
|
|
186
|
+
c = Object.new
|
|
187
|
+
r = Stretchr::Request.new({client: c})
|
|
188
|
+
assert_equal "people/1/cars", r.at("people/1/cars").path, "Should have set the path completely"
|
|
189
|
+
end
|
|
184
190
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stretchr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Quinn
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A gem for interacting with your stretchr data
|
|
14
14
|
email: ryan@mazondo.com
|