zooppa_api_v3 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +117 -0
- data/Rakefile +1 -0
- data/lib/zooppa_api_v3.rb +209 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/zooppa_api_v3_spec.rb +166 -0
- data/zooppa_api_v3.gemspec +28 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7a46c2595a84886dda4ef65348161ed576ddc31
|
4
|
+
data.tar.gz: d7d016f13370f4bcda2e582aaaec144249448624
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8bba0d8f7c4dc8ac301c39be48c1653895485ba8ae99176be84ca227e4a3cf5e39a935d7a23fb872aac03175297387a768216b33fda8eeb54bd7d5103b15470
|
7
|
+
data.tar.gz: 8e4b3cdc5ea7f35127cf8820cf0567e2770dde5940f27c20a23920c4d7f46f2aff0fc023d1560b966305f502c8f440750c1521ced7f1373d828ebf7487207ede
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
zooppa_api_v3
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0-p451
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ulrich Soeffing
|
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,117 @@
|
|
1
|
+
# ZooppaApiV3
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zooppa_api_v3'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zooppa_api_v3
|
18
|
+
|
19
|
+
## Requirements & Limitations
|
20
|
+
|
21
|
+
Requires ruby 2.0 or greater and works only with API V3.
|
22
|
+
|
23
|
+
|
24
|
+
## Installation & Setup
|
25
|
+
|
26
|
+
1. Add to `Gemfile`: `gem 'zooppa_api_v3'`
|
27
|
+
|
28
|
+
2. Add to `config/initializers/zooppa_api_v3.rb`:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
ZOOPPA_API = ZooppaApiV3.new( app_secret: 'app_secret',
|
32
|
+
app_id: 'app_id'
|
33
|
+
)
|
34
|
+
```
|
35
|
+
|
36
|
+
Possible configuration options:
|
37
|
+
|
38
|
+
1. api_host: specify host of API (default: http://zooppa.com/)
|
39
|
+
2. app_secret: Secret key of the registered Oauth App
|
40
|
+
3. app_id: ID of the registered Oauth App
|
41
|
+
4. encrypt: #authenticate method returns encrypted access token if true (default: true)
|
42
|
+
5. version: specify version of API (default: 'v3')
|
43
|
+
6. iv: the Initialization vector used for encryption (use your Rails secret_key_base here, for instance)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
###Authentication:
|
50
|
+
|
51
|
+
`ZOOPPA_API.authenticate('email@email.com', 'pass')`
|
52
|
+
|
53
|
+
If authentication was successful, it returns the access token (encrypted if encrypt is set to true) or returns JSON with an error key and message.
|
54
|
+
|
55
|
+
###Find a resource
|
56
|
+
|
57
|
+
`ZOOPPA_API.ads.find(1).execute('token')`
|
58
|
+
|
59
|
+
Find ad with id 1
|
60
|
+
|
61
|
+
`ZOOPPA_API.contests.find(1).execute('token')`
|
62
|
+
|
63
|
+
Find contest with id 1
|
64
|
+
|
65
|
+
###Get collection of a resource
|
66
|
+
|
67
|
+
`ZOOPPA_API.contests.execute('token')`
|
68
|
+
|
69
|
+
Gets the first 10 contests
|
70
|
+
|
71
|
+
###Pagination
|
72
|
+
|
73
|
+
`ZOOPPA_API.contests.page(2).per_page(100).execute('token')`
|
74
|
+
|
75
|
+
Get 100 contests with offset 100
|
76
|
+
|
77
|
+
###Filtering
|
78
|
+
|
79
|
+
`ZOOPPA_API.ads.where('contest_id,=,1').execute('token')`
|
80
|
+
|
81
|
+
Get ads which contest_id attributes equals 1
|
82
|
+
|
83
|
+
`ZOOPPA_API.ads.where('contest_id,=,1', 'resource_type,=,video').execute('token')`
|
84
|
+
|
85
|
+
Get ads which contest_id attributes equals 1 and resource_type equals 'video'
|
86
|
+
|
87
|
+
###Sorting
|
88
|
+
|
89
|
+
`ZOOPPA_API.ads.sort('title ASC').execute('token')`
|
90
|
+
|
91
|
+
Sort ads by title ascending
|
92
|
+
|
93
|
+
###Combine filtering, sorting and pagination
|
94
|
+
|
95
|
+
`ZOOPPA_API.ads.where('contest_id,=,1', 'resource_type,=,video').sort('title DESC').page(2).per_page(9)execute('token')`
|
96
|
+
|
97
|
+
###Delete a resource
|
98
|
+
|
99
|
+
`ZOOPPA_API.users.find(1).delete.execute('token')`
|
100
|
+
|
101
|
+
###Update a resource
|
102
|
+
|
103
|
+
`ZOOPPA_API.users.find(1).update_attributes({user: { name: 'new' }}).execute('token')`
|
104
|
+
|
105
|
+
###Create a resource
|
106
|
+
|
107
|
+
`ZOOPPA_API.users.create({user: { name: 'new' }}).execute('token')`
|
108
|
+
|
109
|
+
|
110
|
+
### General
|
111
|
+
|
112
|
+
If the request you make requires authentication, you need to pass in the token into the `.execute` method. If authentication is not needed, you don't need to pass in any argument.
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'oauth2'
|
6
|
+
require 'encryptor'
|
7
|
+
|
8
|
+
|
9
|
+
class ZooppaApiV3
|
10
|
+
|
11
|
+
# Initializes the Rest Request
|
12
|
+
# resource: string - resource name - must be plural (i.e. 'invitations', 'companies')
|
13
|
+
# method: sym - HTTP VERB (:post, :put, :delete, :get)
|
14
|
+
# cookies: Rails cookies Object - from controller - is required when 'authenticate' is set to true
|
15
|
+
# params: hash - params from controller
|
16
|
+
# id: integer - resource id - required for show, update & destroy action only
|
17
|
+
# authenticate: boolean - API call requires authentication (true) or not (false)?
|
18
|
+
# api_version: string - specifies version of API - default: v2
|
19
|
+
#
|
20
|
+
# Here we use KEYWORD ARGUMENTS (new in ruby 2.0.0): http://magazine.rubyist.net/?Ruby200SpecialEn-kwarg
|
21
|
+
def initialize(**args)
|
22
|
+
@api_host = args.fetch(:api_host) { 'http://localhost:3000/' }
|
23
|
+
@version = args.fetch(:version) { 'v3' }
|
24
|
+
@app_secret = args.fetch(:app_secret) { 'app_secret' }
|
25
|
+
@app_id = args.fetch(:app_id) { 'app_id' }
|
26
|
+
@encrypt = args.fetch(:encrypt) { true }
|
27
|
+
# needed for encrypting the access token
|
28
|
+
@iv = args.fetch(:iv) { '' }
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(method,*args,&block)
|
32
|
+
eigenclass = class << self; self; end
|
33
|
+
eigenclass.class_eval do
|
34
|
+
define_method(method) do
|
35
|
+
@resource = method.to_s
|
36
|
+
return self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
send(method, *args, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_attributes(params)
|
43
|
+
@method = :patch
|
44
|
+
@params = params
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def create(params)
|
49
|
+
@method = :post
|
50
|
+
@params = params
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def where(*args)
|
55
|
+
@method = :get
|
56
|
+
@filter_params = ''
|
57
|
+
args.each_with_index do |filter, index|
|
58
|
+
@filter_params += '&' unless @filter_params == ''
|
59
|
+
@filter_params += "filters[filter_#{index}]=#{filter}"
|
60
|
+
end
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def sort(sort_by)
|
65
|
+
@method = :get
|
66
|
+
@sort_params = "sort_by#{sort_by.to_query('')}"
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def find(id)
|
71
|
+
@method = :get
|
72
|
+
@id = id.to_s
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def page(page)
|
77
|
+
@method = :get
|
78
|
+
@page_params = "page=#{page.to_s}"
|
79
|
+
self
|
80
|
+
end
|
81
|
+
|
82
|
+
def per_page(per_page)
|
83
|
+
@method = :get
|
84
|
+
@per_page_params = "per_page=#{per_page.to_s}"
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
def delete
|
89
|
+
@method = :delete
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
def execute(token = nil)
|
94
|
+
@url = build_url
|
95
|
+
|
96
|
+
add_auth_token(token) if token
|
97
|
+
if [:post, :put, :patch].include?(@method)
|
98
|
+
JSON.parse(RestClient.send(@method, @url, @params))
|
99
|
+
else
|
100
|
+
JSON.parse(RestClient.send(@method, @url))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Builds the URL (adds an id of provided)
|
105
|
+
def build_url
|
106
|
+
url = @api_host + 'api/' + @version + '/' + @resource
|
107
|
+
url += '/' + @id if @id
|
108
|
+
url += '.json'
|
109
|
+
if [:delete, :get].include?(@method)
|
110
|
+
@params = complete_parameters(query_params, pagination_params) if [:delete, :get].include?(@method)
|
111
|
+
url += '?' + @params unless @params == ''
|
112
|
+
end
|
113
|
+
url
|
114
|
+
end
|
115
|
+
|
116
|
+
def complete_parameters(query_params, pagination_params)
|
117
|
+
if query_params != '' && pagination_params != ''
|
118
|
+
return [query_params, pagination_params].join('&')
|
119
|
+
elsif query_params == ''
|
120
|
+
return pagination_params
|
121
|
+
elsif pagination_params == ''
|
122
|
+
return query_params
|
123
|
+
else
|
124
|
+
return ''
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def query_params
|
129
|
+
query_params = ''
|
130
|
+
if @filter_params
|
131
|
+
query_params += @filter_params
|
132
|
+
end
|
133
|
+
|
134
|
+
if @sort_params
|
135
|
+
query_params += '&' unless query_params == ''
|
136
|
+
query_params += @sort_params
|
137
|
+
end
|
138
|
+
return query_params
|
139
|
+
end
|
140
|
+
|
141
|
+
def pagination_params
|
142
|
+
pagination_params = ''
|
143
|
+
if @page_params
|
144
|
+
pagination_params += @page_params
|
145
|
+
end
|
146
|
+
|
147
|
+
if @per_page_params
|
148
|
+
pagination_params += '&' unless pagination_params == ''
|
149
|
+
pagination_params += @per_page_params
|
150
|
+
end
|
151
|
+
return pagination_params
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def prepare_request(resource, **args)
|
156
|
+
@resource = resource
|
157
|
+
@method = args.fetch(:method) { :get }
|
158
|
+
@id = args.fetch(:id) { nil }
|
159
|
+
@params = args.fetch(:params) { {} }
|
160
|
+
@cookies = args.fetch(:cookies) { {} }
|
161
|
+
@authenticate = args.fetch(:authenticate) { false }
|
162
|
+
@url = build_url
|
163
|
+
|
164
|
+
if @authenticate
|
165
|
+
fail Exceptions::MissingAuthToken unless @cookies.key?(:auth_token)
|
166
|
+
add_auth_token
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Adds the auth_token to the params hash or url (depending on the HTTP verb)
|
171
|
+
def add_auth_token(token)
|
172
|
+
if @encrypt && @authenticate
|
173
|
+
token = decrypt_token(token)
|
174
|
+
end
|
175
|
+
|
176
|
+
if [:get, :delete].include?(@method) && !@params.empty?
|
177
|
+
@url += '&access_token=' + token
|
178
|
+
elsif [:get, :delete].include?(@method) && @params.empty?
|
179
|
+
@url += '?access_token=' + token
|
180
|
+
else
|
181
|
+
@params.merge!(access_token: token)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def authenticate(email, password)
|
186
|
+
client = OAuth2::Client.new(
|
187
|
+
@app_id,
|
188
|
+
@app_secret,
|
189
|
+
site: @api_host
|
190
|
+
)
|
191
|
+
token = client.password.get_token(email, password).token
|
192
|
+
@encrypt ? encrypt_token(token) : token
|
193
|
+
rescue => e
|
194
|
+
parse_error_message(e)
|
195
|
+
end
|
196
|
+
|
197
|
+
def decrypt_token(encrypted_token)
|
198
|
+
Encryptor.decrypt(encrypted_token, :key => @app_id, :iv => @iv, :salt => @app_secret)
|
199
|
+
end
|
200
|
+
|
201
|
+
def encrypt_token(token)
|
202
|
+
Encryptor.encrypt(token, :key => @app_id, :iv => @iv, :salt => @app_secret)
|
203
|
+
end
|
204
|
+
|
205
|
+
def parse_error_message(e)
|
206
|
+
msg = e.try(:code) == 'invalid_resource_owner' ? 'Invalid email or password.' : 'There seems to be a connection problem'
|
207
|
+
{ error: msg }
|
208
|
+
end
|
209
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'zooppa_api_v3'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
RSpec.configure do |c|
|
6
|
+
c.mock_with :rspec
|
7
|
+
c.color = true
|
8
|
+
|
9
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
c.filter_run :focus => true
|
11
|
+
c.run_all_when_everything_filtered = true
|
12
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
puts ZooppaApiV3
|
6
|
+
|
7
|
+
describe ZooppaApiV3 do
|
8
|
+
|
9
|
+
context '#new' do
|
10
|
+
subject(:zooppa_api) { ZooppaApiV3 }
|
11
|
+
|
12
|
+
it 'sets default @api_host' do
|
13
|
+
expect(zooppa_api.new.instance_variable_get('@api_host')).to eq 'http://localhost:3000/'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets default @version' do
|
17
|
+
expect(zooppa_api.new.instance_variable_get('@version')).to eq 'v3'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sets default @encrypt to true' do
|
21
|
+
expect(zooppa_api.new.instance_variable_get('@encrypt')).to eq true
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets @app_secret' do
|
25
|
+
expect(zooppa_api.new(app_secret: 'secret').instance_variable_get('@app_secret')).to eq 'secret'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets @app_id' do
|
29
|
+
expect(zooppa_api.new(app_id: 'id').instance_variable_get('@app_id')).to eq 'id'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
context '#build_url' do
|
35
|
+
subject(:zooppa_api) { ZooppaApiV3.new }
|
36
|
+
|
37
|
+
context 'Given .where is called with one filter argument' do
|
38
|
+
it 'returns correct url' do
|
39
|
+
expect(zooppa_api.ads.where('contest_id,=,1').build_url).to eq 'http://localhost:3000/api/v3/ads.json?filters[filter_0]=contest_id,=,1'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'Given .where is called with two filter argument' do
|
44
|
+
it 'returns correct url' do
|
45
|
+
expect(zooppa_api.ads.where('contest_id,=,1', 'resource_type,=,video').build_url).to eq 'http://localhost:3000/api/v3/ads.json?filters[filter_0]=contest_id,=,1&filters[filter_1]=resource_type,=,video'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'Given .sort is called an argument' do
|
50
|
+
it 'returns correct url' do
|
51
|
+
expect(zooppa_api.ads.sort('title ASC').build_url).to eq 'http://localhost:3000/api/v3/ads.json?sort_by=title+ASC'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'Given .sort is called with an argument and .where with two filter argument' do
|
56
|
+
it 'returns correct url' do
|
57
|
+
expect(zooppa_api.ads.where('contest_id,=,1', 'resource_type,=,video').sort('title ASC').build_url).to eq 'http://localhost:3000/api/v3/ads.json?filters[filter_0]=contest_id,=,1&filters[filter_1]=resource_type,=,video&sort_by=title+ASC'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'Given .find(1) is called' do
|
62
|
+
it 'returns the correct url' do
|
63
|
+
expect(zooppa_api.ads.find(1).build_url).to eq 'http://localhost:3000/api/v3/ads/1.json'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'Given .page(1) is called' do
|
68
|
+
it 'returns the correct url' do
|
69
|
+
expect(zooppa_api.ads.page(1).build_url).to eq 'http://localhost:3000/api/v3/ads.json?page=1'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'Given .per_page(10) is called' do
|
74
|
+
it 'returns the correct url' do
|
75
|
+
expect(zooppa_api.ads.per_page(10).build_url).to eq 'http://localhost:3000/api/v3/ads.json?per_page=10'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'Given .per_page(10) and .page(1) is called' do
|
80
|
+
it 'returns the correct url' do
|
81
|
+
expect(zooppa_api.ads.page(1).per_page(10).build_url).to eq 'http://localhost:3000/api/v3/ads.json?page=1&per_page=10'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'Given .per_page(10), .page(1), .where with two filter argument and .sort() is called' do
|
86
|
+
it 'returns the correct url' do
|
87
|
+
expect(zooppa_api.ads.page(1).per_page(10).where('contest_id,=,1', 'resource_type,=,video').sort('title ASC').build_url).to eq 'http://localhost:3000/api/v3/ads.json?filters[filter_0]=contest_id,=,1&filters[filter_1]=resource_type,=,video&sort_by=title+ASC&page=1&per_page=10'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context '#execute' do
|
93
|
+
subject(:zooppa_api) { ZooppaApiV3.new }
|
94
|
+
|
95
|
+
context 'Given .find(1) is called with .execute(false)' do
|
96
|
+
it 'it calls Restclient.send with :get as method and correct url' do
|
97
|
+
expect(RestClient).to receive(:send).with(:get, 'http://localhost:3000/api/v3/ads/1.json').and_return({}.to_json)
|
98
|
+
zooppa_api.ads.find(1).execute(false)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'Given .find(1) is called with .execute(token)' do
|
103
|
+
it 'it calls Restclient.send with :get as method and correct url with access token' do
|
104
|
+
expect(RestClient).to receive(:send).with(:get, 'http://localhost:3000/api/v3/ads/1.json?access_token=token').and_return({}.to_json)
|
105
|
+
zooppa_api.ads.find(1).execute('token')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
context 'Given .where("contest_id,=,1") is called' do
|
111
|
+
it 'it calls Restclient.send with :get as method and correct url' do
|
112
|
+
expect(RestClient).to receive(:send).with(:get, 'http://localhost:3000/api/v3/ads.json?filters[filter_0]=contest_id,=,1').and_return({}.to_json)
|
113
|
+
zooppa_api.ads.where('contest_id,=,1').execute
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'Given .where("contest_id,=,1") is called with .execute(token)' do
|
118
|
+
it 'it calls Restclient.send with :get as method and correct url with access token' do
|
119
|
+
expect(RestClient).to receive(:send).with(:get, 'http://localhost:3000/api/v3/ads.json?filters[filter_0]=contest_id,=,1&access_token=token').and_return({}.to_json)
|
120
|
+
zooppa_api.ads.where('contest_id,=,1').execute('token')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'Given .delete is called' do
|
125
|
+
it 'it calls Restclient.send with :delete as method and correct url' do
|
126
|
+
expect(RestClient).to receive(:send).with(:delete, 'http://localhost:3000/api/v3/ads/1.json').and_return({}.to_json)
|
127
|
+
zooppa_api.ads.find(1).delete.execute
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'Given .delete is called with execute(token)' do
|
132
|
+
it 'it calls Restclient.send with :delete as method and correct url' do
|
133
|
+
expect(RestClient).to receive(:send).with(:delete, 'http://localhost:3000/api/v3/ads/1.json?access_token=token').and_return({}.to_json)
|
134
|
+
zooppa_api.ads.find(1).delete.execute('token')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'Given .create is called' do
|
139
|
+
it 'it calls Restclient.send with :post method, correct url and parameters' do
|
140
|
+
expect(RestClient).to receive(:send).with(:post, 'http://localhost:3000/api/v3/ads.json', {ad: {title: 'title'}}).and_return({}.to_json)
|
141
|
+
zooppa_api.ads.create({ad: {title: 'title'}}).execute
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'Given .create is called with .execute(token)' do
|
146
|
+
it 'it calls Restclient.send with :post method, correct url and parameters with access token' do
|
147
|
+
expect(RestClient).to receive(:send).with(:post, 'http://localhost:3000/api/v3/ads.json', { ad: { title: 'title'}, access_token: 'token'}).and_return({}.to_json)
|
148
|
+
zooppa_api.ads.create({ad: {title: 'title'}}).execute('token')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'Given .update_attributes is called' do
|
153
|
+
it 'it calls Restclient.send with :patch method, correct url and parameters' do
|
154
|
+
expect(RestClient).to receive(:send).with(:patch, 'http://localhost:3000/api/v3/ads/1.json', {ad: {title: 'title'}}).and_return({}.to_json)
|
155
|
+
zooppa_api.ads.find(1).update_attributes({ad: {title: 'title'}}).execute
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'Given .update_attributes is called with .execute(token)' do
|
160
|
+
it 'it calls Restclient.send with :patch method, correct url and parameters with access token' do
|
161
|
+
expect(RestClient).to receive(:send).with(:patch, 'http://localhost:3000/api/v3/ads/1.json', { ad: { title: 'title' }, access_token: 'token' }).and_return({}.to_json)
|
162
|
+
zooppa_api.ads.find(1).update_attributes({ad: {title: 'title'}}).execute('token')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
# require 'zooppa_api_v3/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zooppa_api_v3"
|
8
|
+
spec.version = '0.0.1'
|
9
|
+
spec.authors = ["Ulrich Soeffing"]
|
10
|
+
spec.email = ["ulrich_soeffing@gmx.de"]
|
11
|
+
spec.description = "Wrapper for the Zooppa api v3"
|
12
|
+
spec.summary = "Wrapper for the Zooppa api v3"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_runtime_dependency 'rest-client'
|
25
|
+
spec.add_runtime_dependency 'oauth2'
|
26
|
+
spec.add_runtime_dependency 'encryptor'
|
27
|
+
spec.add_runtime_dependency 'activesupport'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zooppa_api_v3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ulrich Soeffing
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rspec
|
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: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oauth2
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: encryptor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
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: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Wrapper for the Zooppa api v3
|
112
|
+
email:
|
113
|
+
- ulrich_soeffing@gmx.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .ruby-gemset
|
120
|
+
- .ruby-version
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- lib/zooppa_api_v3.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/zooppa_api_v3_spec.rb
|
128
|
+
- zooppa_api_v3.gemspec
|
129
|
+
homepage: ''
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.2.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Wrapper for the Zooppa api v3
|
153
|
+
test_files:
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- spec/zooppa_api_v3_spec.rb
|