beemusic_api 0.0.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 +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENCE.txt +0 -0
- data/README.rdoc +26 -0
- data/Rakefile +1 -0
- data/lib/beemusic_api.rb +186 -0
- data/lib/beemusic_api/version.rb +3 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aad6d27e987122016cb639fc544b161b56e7a3a1
|
4
|
+
data.tar.gz: 5388a4616c05527a681288afdf00c75dd042bb72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6afb2fa8e80f30557f4897d66d33794a5fffc6187d6940de347e73d30062e863cb94cc38c507232fb9d3ef5a615271d653c20c69c68c0fe57c8037d7c7a38b06
|
7
|
+
data.tar.gz: 1c4be90f34c3012c1a2bff84e27f910a47c13046603d7f924124de8c87d1e5d0b30850d8d4f69f983b053dfa290d3d63308406198396d787246b06968feb4bce
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENCE.txt
ADDED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
== Beemusic API
|
2
|
+
|
3
|
+
A gem for using Beemusic WebService
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
You can install this gem by adding this line in your Gemfile :
|
8
|
+
|
9
|
+
gem 'beemusic_api', :git => 'git@git.idol.io:beemusic/beemusic_api.git'
|
10
|
+
|
11
|
+
And then :
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
client = BeemusicApi::HttpClient.new('<URL>')
|
17
|
+
client.authenticate('<Login>', '<Password>')
|
18
|
+
|
19
|
+
response = client.get('/product', params: { per_page: 10, page: 1 })
|
20
|
+
|
21
|
+
JSON.parse(response)
|
22
|
+
=> {"IdProduct"=>0, "RefProvider"=>"0885150337684", "IdDistributor"=>"HAR", "DateModification"=>"2014-01-10T15:45:37+01:00", "Mask"=>0, "Grid"=>"", "CatalogNumber"=>"233768", "Title"=>"Grand River Crossings", "ShortTitle"=>"G.ALLEN/Grand River", "ReceipTitle"=>"G.ALLEN/Grand River", "SubTitle"=>nil, "Version"=>nil, "Argument"=>"Toto", "Pline"=>nil, "Cline"=>nil, "Year"=>nil, "Brand"=>nil, "ContainerType"=>nil, "IsImport"=>false, "IsLimitedEdition"=>nil, "IsCompilation"=>nil, "IsExclusive"=>false, "Duration"=>nil, "NbDisk"=>1, "NbTrack"=>nil, "NbBundle"=>nil, "NbBonusTrack"=>nil, "Sell"=>"2013-09-24T00:00:00", "Withdraw"=>nil, "Available"=>2, "OrderStart"=>nil, "OrderEnd"=>nil, "OrderAvailable"=>nil, "ReleaseType"=>nil, "RecordingType"=>nil, "IdLabel"=>10831, "IdCountry"=>0, "IdGenre"=>10501, "IdMedia"=>11, "Packaging"=>nil}
|
23
|
+
|
24
|
+
== Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2014 IDOL
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/beemusic_api.rb
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'beemusic_api/version'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module BeemusicApi
|
5
|
+
class HttpClient
|
6
|
+
def initialize(server_url, debug = true)
|
7
|
+
@server_url = server_url
|
8
|
+
@debug = debug
|
9
|
+
end
|
10
|
+
|
11
|
+
def authenticate(user, password, session = {})
|
12
|
+
unless session.empty?
|
13
|
+
@cookies = session
|
14
|
+
@user = user
|
15
|
+
@password = password
|
16
|
+
|
17
|
+
return session
|
18
|
+
end
|
19
|
+
|
20
|
+
response = post(
|
21
|
+
"/auth/credentials",
|
22
|
+
{
|
23
|
+
UserName: user,
|
24
|
+
Password: password,
|
25
|
+
RememberMe: true
|
26
|
+
}
|
27
|
+
)
|
28
|
+
|
29
|
+
if response.valid?
|
30
|
+
@cookies = response.cookies
|
31
|
+
@user = user
|
32
|
+
@password = password
|
33
|
+
end
|
34
|
+
|
35
|
+
response.cookies
|
36
|
+
end
|
37
|
+
|
38
|
+
def put(url, params)
|
39
|
+
if @debug
|
40
|
+
puts "url = #{url}"
|
41
|
+
puts "params = #{params}"
|
42
|
+
end
|
43
|
+
|
44
|
+
headers = {
|
45
|
+
content_type: :json,
|
46
|
+
accept: :json
|
47
|
+
}
|
48
|
+
|
49
|
+
headers.merge!(cookies: @cookies) unless @cookies.nil?
|
50
|
+
puts "headers = #{headers}"
|
51
|
+
|
52
|
+
RequestResponse.new(
|
53
|
+
RestClient.put(
|
54
|
+
"#{@server_url}/#{url}",
|
55
|
+
params.to_json,
|
56
|
+
headers
|
57
|
+
) do |response, request, result|
|
58
|
+
response
|
59
|
+
end
|
60
|
+
)
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def products(per_page: 10, page: 1)
|
65
|
+
r = JSON.parse(get("/productpaging/#{per_page}/#{page}"))
|
66
|
+
BeemusicApi::Models::Product.build(self, r['Products'], total_entries: r['ItemsCount'].to_i, current_page: r['CurrentPage'].to_i)
|
67
|
+
end
|
68
|
+
|
69
|
+
def product(id)
|
70
|
+
r = JSON.parse(get("/product/#{id}"))
|
71
|
+
BeemusicApi::Models::Product.build(self, r)
|
72
|
+
end
|
73
|
+
|
74
|
+
def upload_binary(url, payload)
|
75
|
+
r = Faraday.new(@server_url, :ssl => {:verify => false}) do |conn|
|
76
|
+
conn.request :multipart
|
77
|
+
conn.request :url_encoded
|
78
|
+
conn.response :logger
|
79
|
+
conn.adapter :net_http
|
80
|
+
conn.headers['Cookie'] = @cookies.collect{|k, v| "#{k}=#{v}"}.join('; ')
|
81
|
+
conn.basic_auth(@user, @password)
|
82
|
+
end
|
83
|
+
|
84
|
+
r.post(url, payload)
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete(url, params = {})
|
88
|
+
if @debug
|
89
|
+
puts "url = #{url}"
|
90
|
+
puts "params = #{params}"
|
91
|
+
end
|
92
|
+
|
93
|
+
params.merge!({
|
94
|
+
params: params[:params].to_json,
|
95
|
+
content_type: :json,
|
96
|
+
accept: :json
|
97
|
+
})
|
98
|
+
|
99
|
+
params.merge!(cookies: @cookies) unless @cookies.nil?
|
100
|
+
|
101
|
+
RequestResponse.new(RestClient.delete("#{@server_url}/#{url}", params)).response
|
102
|
+
end
|
103
|
+
|
104
|
+
def get(url, params = {})
|
105
|
+
if @debug
|
106
|
+
puts "url = #{url}"
|
107
|
+
puts "params = #{params}"
|
108
|
+
end
|
109
|
+
|
110
|
+
params.merge!({
|
111
|
+
params: params[:params].to_json,
|
112
|
+
content_type: :json,
|
113
|
+
accept: :json
|
114
|
+
})
|
115
|
+
|
116
|
+
params.merge!(cookies: @cookies) unless @cookies.nil?
|
117
|
+
|
118
|
+
RequestResponse.new(RestClient.get("#{@server_url}/#{url}", params)).response
|
119
|
+
end
|
120
|
+
|
121
|
+
def post(url, params)
|
122
|
+
if @debug
|
123
|
+
puts "url = #{url}"
|
124
|
+
puts "params = #{params}"
|
125
|
+
end
|
126
|
+
|
127
|
+
headers = {
|
128
|
+
content_type: :json,
|
129
|
+
accept: :json
|
130
|
+
}
|
131
|
+
|
132
|
+
headers.merge!(cookies: @cookies) unless @cookies.nil?
|
133
|
+
puts "headers = #{headers}"
|
134
|
+
|
135
|
+
RequestResponse.new(
|
136
|
+
RestClient.post(
|
137
|
+
"#{@server_url}/#{url}",
|
138
|
+
params.to_json,
|
139
|
+
headers
|
140
|
+
) do |response, request, result|
|
141
|
+
response
|
142
|
+
end
|
143
|
+
)
|
144
|
+
end
|
145
|
+
|
146
|
+
class RequestResponse
|
147
|
+
def initialize(response, debug = true)
|
148
|
+
@response = response
|
149
|
+
@debug = true
|
150
|
+
end
|
151
|
+
|
152
|
+
def cookies
|
153
|
+
@response.cookies
|
154
|
+
end
|
155
|
+
|
156
|
+
def valid?
|
157
|
+
@response.code == 200
|
158
|
+
end
|
159
|
+
|
160
|
+
def code
|
161
|
+
@response.code
|
162
|
+
end
|
163
|
+
|
164
|
+
def message
|
165
|
+
response_body['ResponseStatus']['Message'] rescue nil
|
166
|
+
end
|
167
|
+
|
168
|
+
def stacktrace
|
169
|
+
response_body['ResponseStatus']['StackTrace'] rescue nil
|
170
|
+
end
|
171
|
+
|
172
|
+
def errors
|
173
|
+
response_body['ResponseStatus']['Errors'] rescue nil
|
174
|
+
end
|
175
|
+
|
176
|
+
def response
|
177
|
+
@response
|
178
|
+
end
|
179
|
+
|
180
|
+
private
|
181
|
+
def response_body
|
182
|
+
@body ||= JSON.parse(@response.body)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beemusic_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julien Séveno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.7
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.6.7
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.7
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.6.7
|
33
|
+
description: Make some api calls to Beemusic Webservice
|
34
|
+
email:
|
35
|
+
- julien.seveno@idol.io
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".gitignore"
|
41
|
+
- Gemfile
|
42
|
+
- LICENCE.txt
|
43
|
+
- README.rdoc
|
44
|
+
- Rakefile
|
45
|
+
- lib/beemusic_api.rb
|
46
|
+
- lib/beemusic_api/version.rb
|
47
|
+
homepage: https://idol.io
|
48
|
+
licenses:
|
49
|
+
- "© IDOL"
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 2.1.0
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements:
|
66
|
+
- rest-client, >= 1.6.7
|
67
|
+
rubyforge_project: beemusic_api
|
68
|
+
rubygems_version: 2.4.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Make some api calls to Beemusic Webservice
|
72
|
+
test_files: []
|