takeout 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -12
- data/lib/takeout/client.rb +9 -5
- data/lib/takeout/version.rb +1 -1
- data/takeout.gemspec +1 -1
- 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: 72075d033cab3d057e294b12750acaefa042fa58
|
4
|
+
data.tar.gz: cbdca972755b2ad75c08466c898974533479b39e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f37fca4f63f5194d7e037fdb7c03123bceeb879a883e47494884eb87763cf42633c17523953a9792f040ac4d5c5f1d904c5d103c0eff583b1bb71ee519f8b1
|
7
|
+
data.tar.gz: 8f43aaa7f2f4d5388f532fd2c156ad52061de8aa251e29bdcc86a984ddf33f2f3c7a1607176be6300bfd30d424f7e3649fbe0ab744f364be1b5d3237b9df5b5f
|
data/README.md
CHANGED
@@ -34,26 +34,21 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
The first step is to instantiate a client with the URI and given endpoints you would like the gem to create methods for:
|
36
36
|
|
37
|
-
client = Takeout::Client.new(uri: 'testing.com'
|
37
|
+
client = Takeout::Client.new(uri: 'testing.com')
|
38
38
|
|
39
39
|
This can also be done using block format:
|
40
40
|
|
41
41
|
client = Takeout::Client.new do |client|
|
42
42
|
client.uri = 'testing.com'
|
43
|
-
client.endpoints = {get: [:test, :test2], post: :test2}
|
44
43
|
end
|
45
44
|
|
46
45
|
From here you can begin calling your api methods! They take on the form ```(request_type)_(endpoint_name)```
|
47
|
-
So
|
46
|
+
So our method list would look like:
|
48
47
|
|
49
48
|
client.get_test
|
50
49
|
client.get_test2
|
51
50
|
client.post_test2
|
52
51
|
|
53
|
-
You can at anytime see a list of the methods available to you by running this:
|
54
|
-
|
55
|
-
(client.methods - Object.methods - Takeout::Client.instance_methods(false))
|
56
|
-
|
57
52
|
Results are returned as parsed ruby objects:
|
58
53
|
|
59
54
|
client.get_test
|
@@ -67,7 +62,6 @@ You may do this in either the call or in the client instantiation, however the c
|
|
67
62
|
|
68
63
|
client = Takeout::Client.new do |client|
|
69
64
|
client.uri = 'testing.com'
|
70
|
-
client.endpoints = {get: [:test, :test2], post: :test2}
|
71
65
|
client.extension = 'json'
|
72
66
|
end
|
73
67
|
|
@@ -81,7 +75,6 @@ To define a schema do so in the instantiation of the client:
|
|
81
75
|
|
82
76
|
client = Takeout::Client.new do |client|
|
83
77
|
client.uri = 'testing.com'
|
84
|
-
client.endpoints = {get: [:test, :test2], post: :test2}
|
85
78
|
client.schemas = {get: {test: '/{{endpoint}}{% if param %}/required-param-{{param}}{% endif %}'}
|
86
79
|
end
|
87
80
|
|
@@ -101,7 +94,7 @@ SSL is also supported, and is very easy to flip on.
|
|
101
94
|
|
102
95
|
You can either specify ssl when instantiating the object:
|
103
96
|
|
104
|
-
client = Takeout::Client.new(uri: 'testing.com',
|
97
|
+
client = Takeout::Client.new(uri: 'testing.com', ssl: true)
|
105
98
|
|
106
99
|
Or you can flip it on once already created:
|
107
100
|
|
@@ -117,7 +110,6 @@ Takeout also feature full support for headers:
|
|
117
110
|
|
118
111
|
client = Takeout::Client.new do |client|
|
119
112
|
client.uri = 'testing.com'
|
120
|
-
client.endpoints = {get: [:test, :test2], post: :test2}
|
121
113
|
client.headers = {auth_token: 'asdjhdskjfh23423423'}
|
122
114
|
end
|
123
115
|
|
@@ -132,7 +124,6 @@ Unlike most other features these are simply passed as options to the call:
|
|
132
124
|
|
133
125
|
client = Takeout::Client.new do |client|
|
134
126
|
client.uri = 'testing.com'
|
135
|
-
client.endpoints = {get: [:test, :test2], post: :test2}
|
136
127
|
client.options = {username: 'user', password: 'pass'}
|
137
128
|
end
|
138
129
|
|
data/lib/takeout/client.rb
CHANGED
@@ -83,8 +83,8 @@ module Takeout
|
|
83
83
|
# @return [Hash] options
|
84
84
|
def substitute_template_values(endpoint, request_type, options={})
|
85
85
|
# Gets the proper template for the give CUSTOM_SCHEMA string for this endpoint and substitutes value for it based on give options
|
86
|
-
endpoint_templates = @schemas.fetch(request_type, nil)
|
87
|
-
template = endpoint_templates.fetch(endpoint, nil) if endpoint_templates
|
86
|
+
endpoint_templates = @schemas.fetch(request_type.to_sym, nil)
|
87
|
+
template = endpoint_templates.fetch(endpoint.to_sym, nil) if endpoint_templates
|
88
88
|
|
89
89
|
if template
|
90
90
|
extracted_options, options = extract_template_options(options.merge({endpoint: endpoint}), template)
|
@@ -123,10 +123,10 @@ module Takeout
|
|
123
123
|
curl.password = options[:password]
|
124
124
|
end
|
125
125
|
|
126
|
-
curl.on_success {|response| @parsed_body, @failure = Takeout::Response.new(headers: response.
|
127
|
-
curl.on_redirect {|response| @parsed_body, @failure = Takeout::Response.new(headers: response.
|
126
|
+
curl.on_success {|response| @parsed_body, @failure = Takeout::Response.new(headers: parse_response_headers(response.head), body: Oj.load(response.body_str), response: response), false}
|
127
|
+
curl.on_redirect {|response| @parsed_body, @failure = Takeout::Response.new(headers: parse_response_headers(response.head), body: Oj.load(response.body_str), response: response), false}
|
128
128
|
|
129
|
-
FAILURES.each { |failure_type| curl.send("on_#{failure_type}") {|response| @parsed_body, @failure = Takeout::Response.new(headers: response.
|
129
|
+
FAILURES.each { |failure_type| curl.send("on_#{failure_type}") {|response| @parsed_body, @failure = Takeout::Response.new(headers: parse_response_headers(response.head), body: Oj.load(response.body_str), response: response), true} }
|
130
130
|
end
|
131
131
|
|
132
132
|
raise Takeout::EndpointFailureError.new(curl, request_type, @parsed_body) if @failure
|
@@ -176,6 +176,10 @@ module Takeout
|
|
176
176
|
ssl? ? URI::HTTPS.build(opts) : URI::HTTP.build(opts)
|
177
177
|
end
|
178
178
|
|
179
|
+
def parse_response_headers(header_string)
|
180
|
+
header_string.split("\r\n")[1..-1].map {|x| {x.split(': ')[0].to_sym => x.split(': ')[1]} }.reduce({}, :update)
|
181
|
+
end
|
182
|
+
|
179
183
|
def method_missing(method_sym, *attributes, &block)
|
180
184
|
request_type = method_sym.to_s.scan(/^(?:get|post|put|delete|patch|update)/).first
|
181
185
|
request_name = method_sym.to_s.scan(/(?<=_{1}).*/).first
|
data/lib/takeout/version.rb
CHANGED
data/takeout.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["kglucas93@gmail.com"]
|
11
11
|
spec.summary = %q{A powerful little tool for generating on-the-fly API clients.}
|
12
12
|
spec.description = %q{}
|
13
|
-
spec.homepage = "http://github.com/
|
13
|
+
spec.homepage = "http://github.com/kylegrantlucas/takeout"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = '>= 1.9.3'
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: takeout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Lucas
|
@@ -165,7 +165,7 @@ files:
|
|
165
165
|
- spec/support/fixtures/post.json
|
166
166
|
- spec/support/fixtures/posts.json
|
167
167
|
- takeout.gemspec
|
168
|
-
homepage: http://github.com/
|
168
|
+
homepage: http://github.com/kylegrantlucas/takeout
|
169
169
|
licenses:
|
170
170
|
- MIT
|
171
171
|
metadata: {}
|