Class: DigitsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/digit_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(digit_params) ⇒ DigitsClient

Returns a new instance of DigitsClient.



4
5
6
7
8
9
10
11
# File 'lib/digit_client.rb', line 4

def initialize(digit_params)
  @digits_credentials = digit_params
  @user_id = digit_params[:user_id]
  @phone_no = digit_params[:number]
  @auth_token = digit_params[:auth_token]
  @auth_token_secret = digit_params[:auth_token_secret]
  @auth_headers = digit_params[:auth_headers]
end

Instance Method Details

#dataObject



13
14
15
16
17
18
19
# File 'lib/digit_client.rb', line 13

def data
	if verified
		{result: true,data: response}
	else
		{result: false,message: "Wrong credentials supplied!"}
	end	
end

#headerObject



33
34
35
# File 'lib/digit_client.rb', line 33

def header
	{"Authorization" => @auth_headers['X-Verify-Credentials-Authorization']}
end

#responseObject



21
22
23
# File 'lib/digit_client.rb', line 21

def response
	HTTParty.get(url, :headers => header)
end

#urlObject



37
38
39
# File 'lib/digit_client.rb', line 37

def url
	@auth_headers["X-Auth-Service-Provider"]
end

#verifiedObject



25
26
27
28
29
30
31
# File 'lib/digit_client.rb', line 25

def verified
  if response["phone_number"] != @phone_no || response["id_str"] != @user_id || response["access_token"]["token"] != @auth_token || response["access_token"]["secret"] != @auth_token_secret
    	false
	else
		true
  end    
end