Module: AmendiaRemote::Api

Defined in:
lib/amendia_remote/api.rb

Defined Under Namespace

Classes: CouldNotConnectError

Class Method Summary collapse

Class Method Details

.authorize(email, password) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/amendia_remote/api.rb', line 7

def self.authorize(email, password)
    payload = {
        'email' => email,
        'password' => password,
    }.to_json   

    remote_response payload, AmendiaRemote.config.authorize[:url], 'post'
end

.get_common_user_api_tokenObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/amendia_remote/api.rb', line 30

def self.get_common_user_api_token
    response = self.authorize(
        AmendiaRemote.config.api_user[:email],
        AmendiaRemote.config.api_user[:password]
    )

    if response && response.code == '200'
        remote_user = JSON.parse(response.body)
        return remote_user['api_token']
    end                   
end

.get_course(id, api_token) ⇒ Object



74
75
76
77
78
79
# File 'lib/amendia_remote/api.rb', line 74

def self.get_course(id, api_token)
    payload = {
        "api_token" => api_token,
    }.to_json                  
    remote_response payload, "#{AmendiaRemote.config.courses[:url]}/#{id}"
end

.get_instrument(id, api_token) ⇒ Object



67
68
69
70
71
72
# File 'lib/amendia_remote/api.rb', line 67

def self.get_instrument(id, api_token)
    payload = {
        "api_token" => api_token,
    }.to_json                  
    remote_response payload, "#{AmendiaRemote.config.instruments[:url]}/#{id}"
end

.get_product(id, api_token) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/amendia_remote/api.rb', line 42

def self.get_product(id, api_token)            
    payload = {
        "api_token" => api_token,
    }.to_json   
    
    remote_response payload, "#{AmendiaRemote.config.product[:url]}/#{id}"
end

.get_product_cat(id, api_token) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/amendia_remote/api.rb', line 59

def self.get_product_cat(id, api_token)
    payload = {
        "api_token" => api_token,
    }.to_json                  

    remote_response payload, "#{AmendiaRemote.config.product_cat[:url]}/#{id}"
end

.get_products(category_id, api_token) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/amendia_remote/api.rb', line 50

def self.get_products(category_id, api_token)
    payload = {
        "api_token" => api_token,
        'category_id' => category_id,
    }.to_json

    remote_response payload, "#{AmendiaRemote.config.product[:url]}"
end

.registration(email, password, api_role, first_name = nil, last_name = nil, phone = nil, recommender = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/amendia_remote/api.rb', line 16

def self.registration(email, password, api_role, first_name=nil, last_name=nil, phone=nil, recommender=nil)
    payload = {'user' => {
        'email' => email.downcase,
        'password' => password,
        'api_role' => api_role,
        'first_name' => first_name,
        'last_name' => last_name,
        'phone' => phone,                    
        'recommender' => recommender,                    
    }}.to_json   

    remote_response payload, AmendiaRemote.config.registration[:url], 'post'
end