amendia_remote 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83fc3681c0d9400f34a65e8b6cbc4b5d006f8e5e
4
- data.tar.gz: 1085a8651c3f054b6944d65f7b65c4f42bf3f7dd
3
+ metadata.gz: 4d4b246e0892a4bca288b49b139ecf0e9acaa204
4
+ data.tar.gz: c81d1a35a7429230f1cfa211795b8b62bfe349a5
5
5
  SHA512:
6
- metadata.gz: 085bf25dd9584db5aa4ea384b58615483ef33ad58224973ca366c556071dc5b5e3930012fb06f52615f14db9dd8295063be1a274915ad3a32bd46e670bd90dfe
7
- data.tar.gz: a829c01ae4955c5481fb8beb891da57833e9e046f80068c9cf8ebd43df5169044c8093dd09f962056bf201e5637a4a5c755fc57eb1db7a40741bfdee95b66c4c
6
+ metadata.gz: 3c47df8a4a970b1f52e4b87c4d5d70779cb8228a02144b7455bfee327f8d2ba27fe8642df8ec852d5d0aad31855f2f033c3c3945bc970f70f9533bf0a9f709f2
7
+ data.tar.gz: e8a9f911794514acb434f376f2b31acc43799fe0b3632956ab7bbe7a89741a90192feeeae7b060eeabd55bc65c1d989b7c068511506d1ae11ca56abce35188f1
@@ -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
@@ -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 = 'amendiatest.com'
8
+ @host = 'amendiatraining.com'
7
9
  @port = '80'
8
- @host_url = 'http://amendiatest.com'
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' }
@@ -1,3 +1,3 @@
1
1
  module AmendiaRemote
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,7 @@
1
+ class InitializerGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def create_initializer_file
5
+ copy_file "amendia_remote.rb", "config/initializers/amendia_remote.rb"
6
+ end
7
+ end
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.2
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-19 00:00:00.000000000 Z
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/amendia_remote/install_generator.rb
53
- - lib/generators/amendia_remote/templates/amendia_remote.rb
54
- - lib/generators/amendia_remote/USAGE
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