allegro-api 0.0.0pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +17 -0
- data/.gitignore +51 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +165 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/allegro-api.gemspec +34 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/allegro.rb +15 -0
- data/lib/allegro/client.rb +38 -0
- data/lib/allegro/http.rb +86 -0
- data/lib/allegro/version.rb +3 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMjU2":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzBjOTJjOTM0NzZkYzNkNGMyMGM0OTEwZTQ3NTg3MjZiZGE2MzA2OGNjNDVj
|
5
|
+
YWIzNzMzNmU2ZGNmZGIzOTU1Nw==
|
6
|
+
data.tar.gz: !binary |-
|
7
|
+
N2FhMzBmYTQ1N2IzMDVkYjliZTA0MTg5ZTE1Mzg5ODY2YjZiODYxMWJjNWI4
|
8
|
+
NTk0ZDA0N2Q1ZTNmMmRhOTViYw==
|
9
|
+
SHA512:
|
10
|
+
metadata.gz: !binary |-
|
11
|
+
NTYyMjdmODBlNDEzN2Y1ZGQ3NTNhM2I1ZGI5NDVhZDA3MDUyN2UyYWE2ZTU0
|
12
|
+
ZThhNmFlNGNkMWJhMjNiZjZmY2ExZDgxZTNiN2VhYTgxZGVhMDVlMDcxNDU5
|
13
|
+
YzM0MjAzNDE5YzA0YmFkMGFmNmNhYjVkMjZlNzIyNjhiNGFlMGI=
|
14
|
+
data.tar.gz: !binary |-
|
15
|
+
NTNjNDdjNzNkNTVhYzVkNDA5ZTBhNGI2ODRlZjFjYjA4NDE5MTI4YzU4NmIy
|
16
|
+
ZGM2YmYxY2ExYzA5NDkzMjE1ODkyZWJmMTBlY2Q1ZGU0YzcyZWFjZGM3Yzdk
|
17
|
+
MmZjYjc2MDY1MTFkNTA0ZGQ0M2I1NGNhNDViMmUwNmMxNjFiNDc=
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
.rspec_status
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
allegro-api (0.0.0pre)
|
5
|
+
json (~> 0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
json (0.4.3)
|
13
|
+
method_source (0.9.2)
|
14
|
+
pry (0.12.2)
|
15
|
+
coderay (~> 1.1.0)
|
16
|
+
method_source (~> 0.9.0)
|
17
|
+
rake (10.5.0)
|
18
|
+
rspec (3.8.0)
|
19
|
+
rspec-core (~> 3.8.0)
|
20
|
+
rspec-expectations (~> 3.8.0)
|
21
|
+
rspec-mocks (~> 3.8.0)
|
22
|
+
rspec-core (3.8.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-expectations (3.8.2)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-mocks (3.8.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.8.0)
|
30
|
+
rspec-support (3.8.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
allegro-api!
|
37
|
+
bundler (~> 1.16)
|
38
|
+
pry (~> 0)
|
39
|
+
rake (~> 10.0)
|
40
|
+
rspec (~> 3.0)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.2
|
data/LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Allegro API
|
2
|
+
|
3
|
+
Simple Ruby REST API client for Allegro API.
|
4
|
+
|
5
|
+
https://developer.allegro.pl/about/#rest-api
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'allegro-api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install allegro-api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# Create client instance and authorize
|
27
|
+
a = Allegro::Client.new('client','secret')
|
28
|
+
|
29
|
+
# Does client authorized sucessfully?
|
30
|
+
a.authorized? # => false
|
31
|
+
```
|
32
|
+
|
33
|
+
## TODO
|
34
|
+
|
35
|
+
* [ ] Write specs!
|
36
|
+
* [ ] Enable specs on travis!
|
37
|
+
* [ ] Add possibilty to setup/change api version
|
38
|
+
* [ ] Handle more `Http::Agent` methods and/or move agent to sepearate `gem`
|
39
|
+
* [ ] Prepare some method for searching offers
|
40
|
+
* [ ] Prepare some methods for other API methods
|
41
|
+
* [ ] Add more TODO-s
|
42
|
+
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kmi3c/allegro-api.
|
data/Rakefile
ADDED
data/allegro-api.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'allegro/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'allegro-api'
|
9
|
+
spec.version = Allegro::VERSION
|
10
|
+
spec.licenses = ['LGPL-3.0']
|
11
|
+
spec.authors = ['Paweł Adamski']
|
12
|
+
spec.email = ['p.adamski@savingcloud.pl']
|
13
|
+
|
14
|
+
spec.summary = %q{Simple API REST client for allegro.pl}
|
15
|
+
spec.homepage = 'https://github.com/kmi3c/allegro-api'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'pry', '~> 0'
|
30
|
+
|
31
|
+
spec.add_dependency('json', '~> 0')
|
32
|
+
|
33
|
+
spec.required_ruby_version = '>= 1.9.3'
|
34
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "allegro"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/allegro.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'allegro/version'
|
4
|
+
require 'allegro/client'
|
5
|
+
require 'allegro/http'
|
6
|
+
|
7
|
+
module Allegro
|
8
|
+
|
9
|
+
attr_reader :client
|
10
|
+
|
11
|
+
def initialize(client_id, secret)
|
12
|
+
@client = Allegro::Client.new(client_id, secret)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Allegro
|
2
|
+
|
3
|
+
AUTH_URI = 'https://allegro.pl/auth/oauth'
|
4
|
+
API_URI = 'https://api.allegro.pl/'
|
5
|
+
|
6
|
+
class Client
|
7
|
+
|
8
|
+
attr_reader :http_agent
|
9
|
+
|
10
|
+
def initialize(client_id, secret, _options = {})
|
11
|
+
@http_agent = Http::Agent.new({client_id: client_id, secret: secret})
|
12
|
+
@authorized = false
|
13
|
+
authorize
|
14
|
+
end
|
15
|
+
|
16
|
+
def authorize
|
17
|
+
response = @http_agent.fetch(
|
18
|
+
auth_url('token'),
|
19
|
+
{ grant_type: 'client_credentials', method: :post }
|
20
|
+
)
|
21
|
+
@access_token = response['access_token']
|
22
|
+
@authorized = true if response && @access_token
|
23
|
+
end
|
24
|
+
|
25
|
+
def authorized?
|
26
|
+
@authorized
|
27
|
+
end
|
28
|
+
|
29
|
+
def api_url(url)
|
30
|
+
[API_URI, url.to_s].join('/')
|
31
|
+
end
|
32
|
+
|
33
|
+
def auth_url(url)
|
34
|
+
[AUTH_URI, url.to_s].join('/')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/allegro/http.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Http
|
4
|
+
class Agent
|
5
|
+
attr_accessor :options, :logger
|
6
|
+
attr_reader :authorized
|
7
|
+
|
8
|
+
def initialize(params = {})
|
9
|
+
@logger = Logger.new(STDOUT)
|
10
|
+
@options = params
|
11
|
+
@authorized = false
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO: split to more atomic methods fe: handle_error, prepare request, etc.
|
15
|
+
def fetch(uri, params = {})
|
16
|
+
uri = URI(uri)
|
17
|
+
params.merge!(default_params)
|
18
|
+
body = []
|
19
|
+
begin
|
20
|
+
session = Net::HTTP.new(uri.host, uri.port)
|
21
|
+
session.use_ssl = uri.scheme == 'https'
|
22
|
+
response = session.start do |http|
|
23
|
+
request = build_request(uri, params)
|
24
|
+
begin
|
25
|
+
http.request(request) do |resp|
|
26
|
+
resp.read_body do |segment|
|
27
|
+
body << segment
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue StandardError => e
|
31
|
+
logger.error e.message
|
32
|
+
ensure
|
33
|
+
body = body.join('')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
case response
|
37
|
+
when Net::HTTPSuccess
|
38
|
+
body = parse_body(body, response.content_type)
|
39
|
+
when Net::HTTPRedirection
|
40
|
+
raise StandardError, response.message
|
41
|
+
else
|
42
|
+
raise StandardError, response.message
|
43
|
+
end
|
44
|
+
rescue StandardError => e
|
45
|
+
logger.error e.message
|
46
|
+
body = []
|
47
|
+
raise e
|
48
|
+
end
|
49
|
+
body
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def build_request(uri, params)
|
55
|
+
method = params[:method]
|
56
|
+
request_params = params.select{|k,v| ![:method, :headers].include?(k)}
|
57
|
+
headers = params[:headers]
|
58
|
+
request = if method == :get
|
59
|
+
uri.query = URI.encode_www_form(params)
|
60
|
+
Net::HTTP::Get.new(uri.request_uri)
|
61
|
+
elsif method == :post
|
62
|
+
request = Net::HTTP::Post.new(uri.path)
|
63
|
+
request.set_form_data(request_params)
|
64
|
+
request
|
65
|
+
end
|
66
|
+
headers.each{|k,v| request[k.to_s] = v }
|
67
|
+
request.basic_auth(options[:client_id], options[:secret])
|
68
|
+
request
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_body(body, content_type)
|
72
|
+
case content_type
|
73
|
+
when /application\/(vnd\.allegro\.public\.v\d+\+json|json)/
|
74
|
+
JSON.parse(body)
|
75
|
+
else
|
76
|
+
body
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def default_params
|
82
|
+
{ method: :get, headers: { accept: 'application/vnd.allegro.public.v1+json'}}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: allegro-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0pre
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paweł Adamski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-21 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: json
|
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
|
+
description:
|
84
|
+
email:
|
85
|
+
- p.adamski@savingcloud.pl
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- allegro-api.gemspec
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/allegro.rb
|
102
|
+
- lib/allegro/client.rb
|
103
|
+
- lib/allegro/http.rb
|
104
|
+
- lib/allegro/version.rb
|
105
|
+
homepage: https://github.com/kmi3c/allegro-api
|
106
|
+
licenses:
|
107
|
+
- LGPL-3.0
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.9.3
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ! '>'
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.3.1
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.7.7
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Simple API REST client for allegro.pl
|
129
|
+
test_files: []
|