amendia_remote 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amendia_remote.rb +4 -0
- data/lib/amendia_remote/api.rb +24 -4
- data/lib/amendia_remote/config.rb +7 -4
- data/lib/amendia_remote/version.rb +1 -1
- data/lib/generators/{amendia_remote → initializer}/USAGE +0 -0
- data/lib/generators/initializer/initializer_generator.rb +7 -0
- data/lib/generators/{amendia_remote → initializer}/templates/amendia_remote.rb +0 -0
- metadata +5 -5
- data/lib/generators/amendia_remote/install_generator.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d4b246e0892a4bca288b49b139ecf0e9acaa204
|
4
|
+
data.tar.gz: c81d1a35a7429230f1cfa211795b8b62bfe349a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c47df8a4a970b1f52e4b87c4d5d70779cb8228a02144b7455bfee327f8d2ba27fe8642df8ec852d5d0aad31855f2f033c3c3945bc970f70f9533bf0a9f709f2
|
7
|
+
data.tar.gz: e8a9f911794514acb434f376f2b31acc43799fe0b3632956ab7bbe7a89741a90192feeeae7b060eeabd55bc65c1d989b7c068511506d1ae11ca56abce35188f1
|
data/lib/amendia_remote.rb
CHANGED
@@ -15,6 +15,10 @@ module AmendiaRemote
|
|
15
15
|
Api.authorize(email, password)
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.registration(email, password, api_role, first_name=nil, last_name=nil, phone=nil, recommender=nil)
|
19
|
+
Api.registration(email, password, api_role, first_name, last_name, phone, recommender)
|
20
|
+
end
|
21
|
+
|
18
22
|
def self.common_user_api_token
|
19
23
|
Api.get_common_user_api_token
|
20
24
|
end
|
data/lib/amendia_remote/api.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module AmendiaRemote
|
2
|
-
module Api
|
2
|
+
module Api
|
3
|
+
|
4
|
+
|
5
|
+
class CouldNotConnectError < StandardError; end
|
6
|
+
|
3
7
|
def self.authorize(email, password)
|
4
8
|
payload = {
|
5
9
|
'email' => email,
|
@@ -9,6 +13,20 @@ module AmendiaRemote
|
|
9
13
|
remote_response payload, AmendiaRemote.config.authorize[:url], 'post'
|
10
14
|
end
|
11
15
|
|
16
|
+
def self.registration(email, password, api_role, first_name=nil, last_name=nil, phone=nil, recommender=nil)
|
17
|
+
payload = {'user' => {
|
18
|
+
'email' => email.downcase,
|
19
|
+
'password' => password,
|
20
|
+
'api_role' => api_role,
|
21
|
+
'first_name' => first_name,
|
22
|
+
'last_name' => last_name,
|
23
|
+
'phone' => phone,
|
24
|
+
'recommender' => recommender,
|
25
|
+
}}.to_json
|
26
|
+
|
27
|
+
remote_response payload, AmendiaRemote.config.registration[:url], 'post'
|
28
|
+
end
|
29
|
+
|
12
30
|
def self.get_common_user_api_token
|
13
31
|
response = self.authorize(
|
14
32
|
AmendiaRemote.config.api_user[:email],
|
@@ -21,11 +39,11 @@ module AmendiaRemote
|
|
21
39
|
end
|
22
40
|
end
|
23
41
|
|
24
|
-
def self.get_product(id, api_token)
|
42
|
+
def self.get_product(id, api_token)
|
25
43
|
payload = {
|
26
44
|
"api_token" => api_token,
|
27
45
|
}.to_json
|
28
|
-
|
46
|
+
|
29
47
|
remote_response payload, "#{AmendiaRemote.config.product[:url]}/#{id}"
|
30
48
|
end
|
31
49
|
|
@@ -74,7 +92,9 @@ module AmendiaRemote
|
|
74
92
|
|
75
93
|
begin
|
76
94
|
response = Net::HTTP.new(host, port).start {|http| http.request(req) }
|
77
|
-
rescue
|
95
|
+
rescue Exception => e
|
96
|
+
raise CouldNotConnectError.new, e
|
97
|
+
#raise CouldNotConnectError.new, message: e, error_code: AmendiaRemote::Config::COULD_NOT_CONNECT, status: 500
|
78
98
|
end
|
79
99
|
|
80
100
|
return response
|
@@ -1,16 +1,19 @@
|
|
1
1
|
module AmendiaRemote
|
2
|
-
class Config
|
3
|
-
attr_accessor :host, :port, :host_url, :access_role, :api_user, :authorize, :product, :product_cat, :instruments, :courses
|
2
|
+
class Config
|
3
|
+
attr_accessor :host, :port, :host_url, :access_role, :api_user, :authorize, :registration, :product, :product_cat, :instruments, :courses
|
4
|
+
|
5
|
+
COULD_NOT_CONNECT = "COULD_NOT_CONNECT_TO_SERVER"
|
4
6
|
|
5
7
|
def initialize
|
6
|
-
@host = '
|
8
|
+
@host = 'amendiatraining.com'
|
7
9
|
@port = '80'
|
8
|
-
@host_url = 'http://
|
10
|
+
@host_url = 'http://amendiatraining.com'
|
9
11
|
@access_role = 'Blue Site User'
|
10
12
|
|
11
13
|
@api_user = { email: 'common@amendia.com', password: 'Z7gvBqJ002x7' }
|
12
14
|
|
13
15
|
@authorize = { url: '/api/v1/users/authorize', method: 'post' }
|
16
|
+
@registration = { url: '/api/v1/users', method: 'post' }
|
14
17
|
@product = { url: '/api/v1/products', method: 'get' }
|
15
18
|
@product_cat = { url: '/api/v1/product_categories', method: 'get' }
|
16
19
|
@instruments = { url: '/api/v1/instruments', method: 'get' }
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amendia_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KCh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -49,9 +49,9 @@ files:
|
|
49
49
|
- lib/amendia_remote/config.rb
|
50
50
|
- lib/amendia_remote/version.rb
|
51
51
|
- lib/amendia_remote.rb
|
52
|
-
- lib/generators/
|
53
|
-
- lib/generators/
|
54
|
-
- lib/generators/
|
52
|
+
- lib/generators/initializer/initializer_generator.rb
|
53
|
+
- lib/generators/initializer/templates/amendia_remote.rb
|
54
|
+
- lib/generators/initializer/USAGE
|
55
55
|
homepage: ''
|
56
56
|
licenses:
|
57
57
|
- MIT
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module AmendiaRemote
|
2
|
-
|
3
|
-
module Generators
|
4
|
-
|
5
|
-
class InstallGenerator < Rails::Generators::Base
|
6
|
-
|
7
|
-
source_root File.expand_path('../templates', __FILE__)
|
8
|
-
|
9
|
-
def generate_config
|
10
|
-
copy_file "amendia_remote.rb", "config/initializers/amendia_remote.rb"
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|