blanket_wrapper 1.0.0
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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +14 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +143 -0
- data/Rakefile +10 -0
- data/blanket.gemspec +34 -0
- data/lib/blanket.rb +71 -0
- data/lib/blanket/response.rb +35 -0
- data/lib/blanket/version.rb +3 -0
- data/spec/blanket/response_spec.rb +38 -0
- data/spec/blanket_spec.rb +158 -0
- data/spec/spec_helper.rb +9 -0
- metadata +245 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cff9cb20ef0765b3930bcc0b4851c512a6939c9c
|
4
|
+
data.tar.gz: e91335deca8e2f7b337b91e8931f60318b7aef1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff4050a1fb7668fb018a69c882b23aa9ab79fa0ee52ad0d8f7f0d668f8f705fb726215d9a27f4936e6477b21a80f4c5bd73601d9b3c8302fff9e72f461ed87fc
|
7
|
+
data.tar.gz: c88e157f9c79c2599872baffbb5ad252b5c5b0f7de30c4a3f5e822102fc80610f5b9fa4f644cb38c56d1cbaf783077a2fbae2094de610c2f5bd1a9b7e6575376
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Bruno Abrantes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Bruno Abrantes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
# Blanket
|
2
|
+
[](https://travis-ci.org/inf0rmer/blanket)
|
3
|
+
[](https://coveralls.io/r/inf0rmer/blanket?branch=master)
|
4
|
+
[](https://codeclimate.com/github/inf0rmer/blanket)
|
5
|
+
|
6
|
+
|
7
|
+
A dead simple API wrapper.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'blanket'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install blanket
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Quick demo
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
github = Blanket.wrap("https://api.github.com")
|
31
|
+
|
32
|
+
# Get some user's info
|
33
|
+
user = github.users('inf0rmer').get
|
34
|
+
user.login
|
35
|
+
# => "inf0rmer"
|
36
|
+
|
37
|
+
# Get a user's repos
|
38
|
+
github.users('inf0rmer').repos.get
|
39
|
+
# => [{
|
40
|
+
# "id": 20000073,
|
41
|
+
# "name": "BAPersistentOperationQueue",
|
42
|
+
# ...
|
43
|
+
# }]
|
44
|
+
```
|
45
|
+
|
46
|
+
### How it works
|
47
|
+
Blanket uses some metaprogramming black magic to wrap an API. Everytime you call a method on a wrapped API, Blanket appends it as a part of the final URL:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
github = Blanket.wrap("https://api.github.com")
|
51
|
+
github.users('inf0rmer').repos.get
|
52
|
+
```
|
53
|
+
|
54
|
+
Here's how the final URL is built, the step by step:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
github = Blanket.wrap("https://api.github.com")
|
58
|
+
# => "https://api.github.com"
|
59
|
+
|
60
|
+
github.users
|
61
|
+
# => "https://api.github.com/users"
|
62
|
+
|
63
|
+
github.users('inf0rmer')
|
64
|
+
# => "https://api.github.com/users/inf0rmer"
|
65
|
+
|
66
|
+
github.users('inf0rmer').repos
|
67
|
+
# => "https://api.github.com/users/inf0rmer/repos"
|
68
|
+
```
|
69
|
+
|
70
|
+
The final `get` method performs a GET HTTP request. You can also use it to append a final part to your request, so you can write something like:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
github = Blanket.wrap("https://api.github.com")
|
74
|
+
github.users.get('inf0rmer')
|
75
|
+
# => "https://api.github.com/users/inf0rmer"
|
76
|
+
```
|
77
|
+
|
78
|
+
### Responses
|
79
|
+
At the moment Blanket only accepts JSON responses. Every request returns a `Blanket::Response` instance, which parses the JSON internally and lets you access keys using dot syntax:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
user = github.users('inf0rmer').get
|
83
|
+
|
84
|
+
user.login
|
85
|
+
# => "inf0rmer"
|
86
|
+
|
87
|
+
user.url
|
88
|
+
# => "https://api.github.com/users/inf0rmer"
|
89
|
+
|
90
|
+
# It even works on nested keys
|
91
|
+
repo = github.repos('inf0rmer').get('blanket')
|
92
|
+
|
93
|
+
repo.owner.login
|
94
|
+
# => "inf0rmer"
|
95
|
+
```
|
96
|
+
|
97
|
+
If the response is an array, all `Enumerable` methods work as expected:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
repos = github.users('inf0rmer').repos.get
|
101
|
+
|
102
|
+
repos.map(&:name)
|
103
|
+
# => ["analytics-ios", "aztec", "fusebox", ...]
|
104
|
+
```
|
105
|
+
|
106
|
+
### Request Parameters
|
107
|
+
Blanket supports appending parameters to your requests:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
api.users(55).get(params: {foo: 'bar'})
|
111
|
+
# => "http://api.example.org/users/55?foo=bar"
|
112
|
+
```
|
113
|
+
|
114
|
+
### Headers
|
115
|
+
HTTP Headers are always useful when accessing an API, so Blanket makes it easy for you to specify them, either globally or on a per-request basis:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
# All requests will carry the `token` header
|
119
|
+
api = Blanket::wrap("http://api.example.org", headers: {token: 'my secret token'})
|
120
|
+
|
121
|
+
# This single request will carry the `foo` header
|
122
|
+
api.users(55).get(headers: {foo: 'bar'})
|
123
|
+
```
|
124
|
+
|
125
|
+
### Extensions
|
126
|
+
Some APIs require you to append an extension to your requests, such as `.json` or `.xml`. Blanket supports this use case, letting you define an extension for all your requests or override it for a single one:
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
# All request URLs are suffixed with ".json"
|
130
|
+
api = Blanket::wrap("http://api.example.org", extension: :json)
|
131
|
+
|
132
|
+
# Requests to "users_endpoint" are suffixed with ".xml" instead
|
133
|
+
users_endpoint = api.users(55)
|
134
|
+
users_endpoint.extension = :xml
|
135
|
+
```
|
136
|
+
|
137
|
+
## Contributing
|
138
|
+
|
139
|
+
1. Fork it ( https://github.com/[my-github-username]/blanket/fork )
|
140
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
141
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
142
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
143
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/blanket.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'blanket/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "blanket_wrapper"
|
8
|
+
spec.version = Blanket::VERSION
|
9
|
+
spec.authors = ["Bruno Abrantes"]
|
10
|
+
spec.email = ["bruno@brunoabrantes.com"]
|
11
|
+
spec.summary = %q{A dead simple API wrapper. Access your data with style.}
|
12
|
+
spec.homepage = "https://github.com/inf0rmer/blanket"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "httparty"
|
21
|
+
spec.add_dependency "recursive-open-struct"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec-nc"
|
27
|
+
spec.add_development_dependency "guard"
|
28
|
+
spec.add_development_dependency "guard-rspec"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
spec.add_development_dependency "pry-remote"
|
31
|
+
spec.add_development_dependency "pry-nav"
|
32
|
+
spec.add_development_dependency "coveralls"
|
33
|
+
spec.add_development_dependency "webmock"
|
34
|
+
end
|
data/lib/blanket.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "blanket/version"
|
2
|
+
require "blanket/response"
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module Blanket
|
6
|
+
def self.wrap(*args)
|
7
|
+
Blanket.new *args
|
8
|
+
end
|
9
|
+
|
10
|
+
class Blanket
|
11
|
+
attr_accessor :headers
|
12
|
+
attr_accessor :extension
|
13
|
+
|
14
|
+
def initialize(base_uri, options={})
|
15
|
+
@base_uri = base_uri
|
16
|
+
@uri_parts = []
|
17
|
+
@headers = (options[:headers].nil?) ? {} : options[:headers]
|
18
|
+
@extension = options[:extension]
|
19
|
+
end
|
20
|
+
|
21
|
+
# RESTful actions
|
22
|
+
[:get, :post, :put, :patch, :delete].each do |action|
|
23
|
+
define_method(action) do |id=nil, options={}|
|
24
|
+
request(action, id, options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(method, *args, &block)
|
29
|
+
Blanket.new uri_from_parts([method, args.first]), {
|
30
|
+
headers: @headers,
|
31
|
+
extension: @extension
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def request(method, id=nil, options={})
|
38
|
+
if id.is_a? Hash
|
39
|
+
options = id
|
40
|
+
id = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
headers = merged_headers(options[:headers])
|
44
|
+
uri = uri_from_parts([id])
|
45
|
+
|
46
|
+
if @extension
|
47
|
+
uri = "#{uri}.#{extension}"
|
48
|
+
end
|
49
|
+
|
50
|
+
response = HTTParty.send(method, uri, {
|
51
|
+
query: options[:params],
|
52
|
+
headers: headers
|
53
|
+
}.reject { |k, v| v.nil? || v.empty? })
|
54
|
+
|
55
|
+
body = (response.respond_to? :body) ? response.body : nil
|
56
|
+
|
57
|
+
(body.is_a? Array) ? body.map(Response.new) : Response.new(body)
|
58
|
+
end
|
59
|
+
|
60
|
+
def merged_headers(headers)
|
61
|
+
headers = @headers.merge(headers != nil ? headers : {})
|
62
|
+
end
|
63
|
+
|
64
|
+
def uri_from_parts(parts)
|
65
|
+
parts
|
66
|
+
.clone
|
67
|
+
.compact
|
68
|
+
.inject(@base_uri.clone) { |memo, part| memo << "/#{part}" }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'recursive-open-struct'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Blanket
|
5
|
+
class Response
|
6
|
+
attr_reader :payload
|
7
|
+
|
8
|
+
def initialize(json_string)
|
9
|
+
json_string ||= "{}"
|
10
|
+
@payload = payload_from_json(JSON.parse(json_string))
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(method, *args, &block)
|
14
|
+
if payload.respond_to? method
|
15
|
+
payload.send method, *args, &block
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def payload_from_json(json)
|
24
|
+
if json
|
25
|
+
parsed = [json].flatten.map do |item|
|
26
|
+
RecursiveOpenStruct.new item, :recurse_over_arrays => true
|
27
|
+
end
|
28
|
+
|
29
|
+
(parsed.count == 1) ? parsed.first : parsed
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'blanket/response'
|
3
|
+
|
4
|
+
describe "Blanket::Response" do
|
5
|
+
describe "Dynamic attribute accessors" do
|
6
|
+
context "With single objects" do
|
7
|
+
let :response do
|
8
|
+
Blanket::Response.new('{"title": "Something", "desc":{"someKey":"someValue","anotherKey":"value"},"main_item":{"values":[{"quantity": 1}, {"quantity": 2}, {"quantity": 3}]}}')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "can access a surface property from a json string as a method" do
|
12
|
+
expect(response.title).to eq("Something")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can access a deep property from a json string as a method" do
|
16
|
+
expect(response.desc.someKey).to eq("someValue")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can access a deep property in an array from a json string as a method" do
|
20
|
+
expect(response.main_item.values[0].quantity).to eq(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "With an array of objects" do
|
25
|
+
let :response do
|
26
|
+
Blanket::Response.new('[{"title": "Something"}, {"title": "Something else"}]')
|
27
|
+
end
|
28
|
+
|
29
|
+
let :titles do
|
30
|
+
response.map(&:title)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can access methods from each item" do
|
34
|
+
expect(titles).to match_array(["Something", "Something else"])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Blanket do
|
4
|
+
let :api do
|
5
|
+
Blanket::wrap("http://api.example.org")
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'Making Requests' do
|
9
|
+
before :each do
|
10
|
+
allow(HTTParty).to receive(:get)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'resets after performing a request' do
|
14
|
+
api.users.get()
|
15
|
+
api.videos.get()
|
16
|
+
|
17
|
+
expect(HTTParty).to have_received(:get).with("http://api.example.org/videos", anything())
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Response" do
|
21
|
+
before :each do
|
22
|
+
stub_request(:get, "http://api.example.org/users").to_return(:body => '{"title": "Something"}')
|
23
|
+
end
|
24
|
+
|
25
|
+
let :response do
|
26
|
+
api.users.get()
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns a Blanket::Response instance" do
|
30
|
+
expect(response).to be_kind_of(Blanket::Response)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'Resource identification' do
|
35
|
+
context 'When using a resource method' do
|
36
|
+
it 'allows identifying a resource' do
|
37
|
+
api.users(55).get()
|
38
|
+
|
39
|
+
expect(HTTParty).to have_received(:get).with("http://api.example.org/users/55", anything())
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'only allows one identifier per resource' do
|
43
|
+
api.users(55, 37).get()
|
44
|
+
|
45
|
+
expect(HTTParty).not_to have_received(:get).with("http://api.example.org/users/55/37", anything())
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'When using #get' do
|
50
|
+
it 'allows identifying the last resource' do
|
51
|
+
api.users(55).videos.get(15)
|
52
|
+
|
53
|
+
expect(HTTParty).to have_received(:get).with("http://api.example.org/users/55/videos/15", anything())
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'Headers' do
|
59
|
+
it 'allows sending headers in a request' do
|
60
|
+
api.users(55).get(headers: {foo: 'bar'})
|
61
|
+
|
62
|
+
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', headers: {foo: 'bar'})
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'allows setting headers globally' do
|
66
|
+
api = Blanket::wrap("http://api.example.org", headers: {token: 'my secret token'})
|
67
|
+
api.users(55).get()
|
68
|
+
|
69
|
+
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', headers: {token: 'my secret token'})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'Parameters' do
|
74
|
+
it 'allows sending parameters in a request' do
|
75
|
+
api.users(55).get(params: {foo: 'bar'})
|
76
|
+
|
77
|
+
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55', query: {foo: 'bar'})
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'URL Extension' do
|
82
|
+
it 'allows setting an extension for a request', :wip => true do
|
83
|
+
users_endpoint = api.users(55)
|
84
|
+
users_endpoint.extension = :json
|
85
|
+
users_endpoint.get
|
86
|
+
|
87
|
+
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55.json', anything())
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'allows setting an extension globally' do
|
91
|
+
api = Blanket::wrap("http://api.example.org", extension: :xml)
|
92
|
+
api.users(55).get
|
93
|
+
|
94
|
+
expect(HTTParty).to have_received(:get).with('http://api.example.org/users/55.xml', anything())
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#get' do
|
100
|
+
before :each do
|
101
|
+
allow(HTTParty).to receive(:get)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'GETs a resource' do
|
105
|
+
api.users.get()
|
106
|
+
|
107
|
+
expect(HTTParty).to have_received(:get).with("http://api.example.org/users", anything())
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#post' do
|
112
|
+
before :each do
|
113
|
+
allow(HTTParty).to receive(:post)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'POSTs a resource' do
|
117
|
+
api.users.post()
|
118
|
+
|
119
|
+
expect(HTTParty).to have_received(:post).with("http://api.example.org/users", anything())
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#put' do
|
124
|
+
before :each do
|
125
|
+
allow(HTTParty).to receive(:put)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'PUTs a resource' do
|
129
|
+
api.users.put()
|
130
|
+
|
131
|
+
expect(HTTParty).to have_received(:put).with("http://api.example.org/users", anything())
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#patch' do
|
136
|
+
before :each do
|
137
|
+
allow(HTTParty).to receive(:patch)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'PATCHes a resource' do
|
141
|
+
api.users.patch()
|
142
|
+
|
143
|
+
expect(HTTParty).to have_received(:patch).with("http://api.example.org/users", anything())
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#delete' do
|
148
|
+
before :each do
|
149
|
+
allow(HTTParty).to receive(:delete)
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'DELETEs a resource' do
|
153
|
+
api.users.delete()
|
154
|
+
|
155
|
+
expect(HTTParty).to have_received(:delete).with("http://api.example.org/users", anything())
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blanket_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Abrantes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: recursive-open-struct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-nc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry-remote
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry-nav
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: coveralls
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description:
|
196
|
+
email:
|
197
|
+
- bruno@brunoabrantes.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- .coveralls.yml
|
203
|
+
- .gitignore
|
204
|
+
- .travis.yml
|
205
|
+
- Gemfile
|
206
|
+
- Guardfile
|
207
|
+
- LICENSE
|
208
|
+
- LICENSE.txt
|
209
|
+
- README.md
|
210
|
+
- Rakefile
|
211
|
+
- blanket.gemspec
|
212
|
+
- lib/blanket.rb
|
213
|
+
- lib/blanket/response.rb
|
214
|
+
- lib/blanket/version.rb
|
215
|
+
- spec/blanket/response_spec.rb
|
216
|
+
- spec/blanket_spec.rb
|
217
|
+
- spec/spec_helper.rb
|
218
|
+
homepage: https://github.com/inf0rmer/blanket
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
metadata: {}
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - '>='
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - '>='
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubyforge_project:
|
238
|
+
rubygems_version: 2.0.14
|
239
|
+
signing_key:
|
240
|
+
specification_version: 4
|
241
|
+
summary: A dead simple API wrapper. Access your data with style.
|
242
|
+
test_files:
|
243
|
+
- spec/blanket/response_spec.rb
|
244
|
+
- spec/blanket_spec.rb
|
245
|
+
- spec/spec_helper.rb
|