Class: Bluevia::BlueviaClient

Inherits:
Object
  • Object
show all
Includes:
BlueviaLogger
Defined in:
lib/bluevia/bluevia_client.rb

Overview

This class is the main client to access Bluevia API. It defines a services factory that provides an isolated way to reach each API. Currently the following APIs are supported:

  • oAuth authentication

  • SMS

  • Advertising

  • Directory

When creating a BlueviaClient instance, basic authentication parameters can be provided:

require ‘bluevia’

bc = BlueviaClient.new(

{ :consumer_key => <YOUR_CONSUMER_KEY>,
  :consumer_secret => <YOUR_CONSUMER_SECRET>,
  :token => <OAUTH_TOKEN>,
  :token_secret => <OAUTH_TOKEN_SECRET>
})

Instance Method Summary collapse

Methods included from BlueviaLogger

#create_logger, #log_level=, #logger, #logger=

Constructor Details

#initialize(params = nil) ⇒ BlueviaClient

Constructor



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bluevia/bluevia_client.rb', line 43

def initialize(params = nil)

  unless params.nil? || params[:uri].nil?
    rest = BaseClient.create_rest_client(params[:uri])
  else
    rest = BaseClient.create_rest_client
  end

  @commercial      = false
  @consumer_key    = nil
  @consumer_secret = nil

  unless params.nil?
    %w(consumer_key consumer_secret token token_secret).each{ |param|
      self.instance_variable_set(:"@#{param}", params[:"#{param}"]) unless params[:"#{param}"].nil?
    }
  end
  
  @factory = ServicesFactory.new(rest)
end

Instance Method Details

#commercial?Boolean

true|false if commercial or sandbox client

Returns:

  • (Boolean)


88
89
90
# File 'lib/bluevia/bluevia_client.rb', line 88

def commercial?
  return @commercial
end

#get_service(_service) ⇒ Object

Retrieves a specific service to call any related API i.e. sms = bc.get_service(:Sms)



67
68
69
70
71
72
73
74
75
# File 'lib/bluevia/bluevia_client.rb', line 67

def get_service(_service)
  service = @factory.get(_service)
  service[:consumer_key]    = @consumer_key   unless @consumer_key.nil?
  service[:consumer_secret] = @consumer_secret unless @consumer_secret.nil?
  service[:token]           = @token          unless @token.nil?
  service[:token_secret]    = @token_secret   unless @token_secret.nil?
  service[:commercial]      = @commercial
  return service
end

#set_commercialObject

Client will get access to commercial APIs



78
79
80
# File 'lib/bluevia/bluevia_client.rb', line 78

def set_commercial
  @commercial = true
end

#set_sandboxObject

Client will get access to sandbox APIs



83
84
85
# File 'lib/bluevia/bluevia_client.rb', line 83

def set_sandbox
  @commercial = false
end