amendia_remote 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/lib/amendia_remote.rb +41 -0
- data/lib/amendia_remote/api.rb +84 -0
- data/lib/amendia_remote/config.rb +20 -0
- data/lib/amendia_remote/version.rb +3 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa83ce3b55c391d10e1bcdd55d70309dfc1365a2
|
4
|
+
data.tar.gz: a4872c191dbd39a97a63a62216561739f22cf1ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8f401914916ea21d3dc283c2b58fc95c05fcccc5b6c7f97b1e95c0f1a57fd60feaac459c71ae5e76840f31e72e5eb454a39e9eff6fa0d0206f1b1268fe30edf
|
7
|
+
data.tar.gz: f3dde0ce74d060895bd5fe5e5d8403c30d1d5eaac44409eb5940d6b2c2c3f82a53a13d6a2456964b9e4ea0460cfdde5bd714a173f43aeabd73fbdd0731e7a5d9
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "amendia_remote/version"
|
2
|
+
require "amendia_remote/config"
|
3
|
+
require "amendia_remote/api"
|
4
|
+
|
5
|
+
module AmendiaRemote
|
6
|
+
def self.config
|
7
|
+
@config ||= Config.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield config
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.authorize(email, password)
|
15
|
+
Api.authorize(email, password)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.common_user_api_token
|
19
|
+
Api.get_common_user_api_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.product(id, api_token)
|
23
|
+
Api.get_product(id, api_token)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.products(category_id, api_token)
|
27
|
+
Api.get_products(category_id, api_token)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.product_cat(id, api_token)
|
31
|
+
Api.get_product_cat(id, api_token)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.instrument(id, api_token)
|
35
|
+
Api.get_instrument(id, api_token)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.course(id, api_token)
|
39
|
+
Api.get_course(id, api_token)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module AmendiaRemote
|
2
|
+
module Api
|
3
|
+
def self.authorize(email, password)
|
4
|
+
payload = {
|
5
|
+
'email' => email,
|
6
|
+
'password' => password,
|
7
|
+
}.to_json
|
8
|
+
|
9
|
+
remote_response payload, AmendiaRemote.config.authorize[:url], 'post'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_common_user_api_token
|
13
|
+
response = self.authorize(
|
14
|
+
AmendiaRemote.config.api_user[:email],
|
15
|
+
AmendiaRemote.config.api_user[:password]
|
16
|
+
)
|
17
|
+
|
18
|
+
if response && response.code == '200'
|
19
|
+
remote_user = JSON.parse(response.body)
|
20
|
+
return remote_user['api_token']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_product(id, api_token)
|
25
|
+
payload = {
|
26
|
+
"api_token" => api_token,
|
27
|
+
}.to_json
|
28
|
+
|
29
|
+
remote_response payload, "#{AmendiaRemote.config.product[:url]}/#{id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_products(category_id, api_token)
|
33
|
+
payload = {
|
34
|
+
"api_token" => api_token,
|
35
|
+
'category_id' => category_id,
|
36
|
+
}.to_json
|
37
|
+
|
38
|
+
remote_response payload, "#{AmendiaRemote.config.product[:url]}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_product_cat(id, api_token)
|
42
|
+
payload = {
|
43
|
+
"api_token" => api_token,
|
44
|
+
}.to_json
|
45
|
+
|
46
|
+
remote_response payload, "#{AmendiaRemote.config.product_cat[:url]}/#{id}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.get_instrument(id, api_token)
|
50
|
+
payload = {
|
51
|
+
"api_token" => api_token,
|
52
|
+
}.to_json
|
53
|
+
remote_response payload, "#{AmendiaRemote.config.instruments[:url]}/#{id}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get_course(id, api_token)
|
57
|
+
payload = {
|
58
|
+
"api_token" => api_token,
|
59
|
+
}.to_json
|
60
|
+
remote_response payload, "#{AmendiaRemote.config.courses[:url]}/#{id}"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def self.remote_response(payload, url, method='get')
|
65
|
+
host = AmendiaRemote.config.host
|
66
|
+
port = AmendiaRemote.config.port
|
67
|
+
|
68
|
+
if method == 'get'
|
69
|
+
req = Net::HTTP::Get.new(url, initheader = {'Content-Type' =>'application/json'})
|
70
|
+
elsif method == 'post'
|
71
|
+
req = Net::HTTP::Post.new(url, initheader = {'Content-Type' =>'application/json'})
|
72
|
+
end
|
73
|
+
req.body = payload
|
74
|
+
|
75
|
+
begin
|
76
|
+
response = Net::HTTP.new(host, port).start {|http| http.request(req) }
|
77
|
+
rescue
|
78
|
+
end
|
79
|
+
|
80
|
+
return response
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AmendiaRemote
|
2
|
+
class Config
|
3
|
+
attr_accessor :host, :port, :host_url, :access_role, :api_user, :authorize, :product, :product_cat, :instruments, :courses
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@host = 'amendiatest.com'
|
7
|
+
@port = '80'
|
8
|
+
@host_url = 'http://amendiatest.com'
|
9
|
+
@access_role = 'Blue Site User'
|
10
|
+
|
11
|
+
@api_user = { email: 'common@amendia.com', password: 'Z7gvBqJ002x7' }
|
12
|
+
|
13
|
+
@authorize = { url: '/api/v1/users/authorize', method: 'post' }
|
14
|
+
@product = { url: '/api/v1/products', method: 'get' }
|
15
|
+
@product_cat = { url: '/api/v1/product_categories', method: 'get' }
|
16
|
+
@instruments = { url: '/api/v1/instruments', method: 'get' }
|
17
|
+
@courses = { url: '/api/v1/courses', method: 'get' }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amendia_remote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- KCh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-19 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
|
+
description: This gem helps use api from amendiatest.com
|
42
|
+
email:
|
43
|
+
- kch@list.ru
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/amendia_remote/api.rb
|
49
|
+
- lib/amendia_remote/config.rb
|
50
|
+
- lib/amendia_remote/version.rb
|
51
|
+
- lib/amendia_remote.rb
|
52
|
+
homepage: ''
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.0.3
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: This gem helps use api from amendiatest.com
|
76
|
+
test_files: []
|