Class: Nexmo::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nexmo/client.rb', line 13

def initialize(options = {})
  @api_key = options[:api_key] || ENV['NEXMO_API_KEY']

  @api_secret = options[:api_secret] || ENV['NEXMO_API_SECRET']

  @signature_secret = options[:signature_secret] || ENV['NEXMO_SIGNATURE_SECRET']

  @application_id = options[:application_id]

  @private_key = options[:private_key]

  @token = nil

  @user_agent = UserAgent.string(options[:app_name], options[:app_version])

  self.http_options = options[:http]

  self.logger = options[:logger] || (defined?(Rails.logger) && Rails.logger)
end

Instance Attribute Details

#api_keyObject



57
58
59
60
61
62
63
64
65
# File 'lib/nexmo/client.rb', line 57

def api_key
  unless @api_key
    raise AuthenticationError.new('No API key provided. ' \
      'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @api_key
end

#api_secretObject



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

def api_secret
  unless @api_secret
    raise AuthenticationError.new('No API secret provided. ' \
      'See https://developer.nexmo.com/concepts/guides/authentication for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @api_secret
end

#application_idObject



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/nexmo/client.rb', line 88

def application_id
  unless @application_id
    raise AuthenticationError.new('No application_id provided. ' \
      'Either provide an application_id, or set an auth token. ' \
      'You can add new applications from the Nexmo dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @application_id
end

#http_optionsObject

Returns the value of attribute http_options.



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

def http_options
  @http_options
end

#private_keyObject



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/nexmo/client.rb', line 100

def private_key
  unless @private_key
    raise AuthenticationError.new('No private_key provided. ' \
      'Either provide a private_key, or set an auth token. ' \
      'You can add new applications from the Nexmo dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/applications for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @private_key
end

#signature_secretObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/nexmo/client.rb', line 77

def signature_secret
  unless @signature_secret
    raise AuthenticationError.new('No signature_secret provided. ' \
      'You can find your signature secret in the Nexmo dashboard. ' \
      'See https://developer.nexmo.com/concepts/guides/signing-messages for details, ' \
      'or email [email protected] if you have any questions.')
  end

  @signature_secret
end

#tokenObject



47
48
49
# File 'lib/nexmo/client.rb', line 47

def token
  @token || JWT.generate({application_id: application_id}, private_key)
end

#user_agentObject

Returns the value of attribute user_agent.



11
12
13
# File 'lib/nexmo/client.rb', line 11

def user_agent
  @user_agent
end

Instance Method Details

#accountObject



116
117
118
# File 'lib/nexmo/client.rb', line 116

def 
  @account ||= Account.new(self)
end

#alertsObject



120
121
122
# File 'lib/nexmo/client.rb', line 120

def alerts
  @alerts ||= Alerts.new(self)
end

#applicationsObject



124
125
126
# File 'lib/nexmo/client.rb', line 124

def applications
  @applications ||= Applications.new(self)
end

#auth_token=(auth_token) ⇒ Object



51
52
53
54
55
# File 'lib/nexmo/client.rb', line 51

def auth_token=(auth_token)
  Kernel.warn "#{self.class}##{__method__} is deprecated (use #token= instead)"

  @token = auth_token
end

#callsObject



128
129
130
# File 'lib/nexmo/client.rb', line 128

def calls
  @calls ||= Calls.new(self)
end

#conversionsObject



132
133
134
# File 'lib/nexmo/client.rb', line 132

def conversions
  @conversions ||= Conversions.new(self)
end

#filesObject



136
137
138
# File 'lib/nexmo/client.rb', line 136

def files
  @files ||= Files.new(self)
end

#loggerObject



39
40
41
# File 'lib/nexmo/client.rb', line 39

def logger
  @logger
end

#logger=(logger) ⇒ Object



43
44
45
# File 'lib/nexmo/client.rb', line 43

def logger=(logger)
  @logger = Logger.new(logger)
end

#messagesObject



140
141
142
# File 'lib/nexmo/client.rb', line 140

def messages
  @messages ||= Messages.new(self)
end

#number_insightObject



144
145
146
# File 'lib/nexmo/client.rb', line 144

def number_insight
  @number_insight ||= NumberInsight.new(self)
end

#numbersObject



148
149
150
# File 'lib/nexmo/client.rb', line 148

def numbers
  @numbers ||= Numbers.new(self)
end

#pricingObject



152
153
154
# File 'lib/nexmo/client.rb', line 152

def pricing
  @pricing ||= PricingTypes.new(self)
end

#redactObject



156
157
158
# File 'lib/nexmo/client.rb', line 156

def redact
  @redact ||= Redact.new(self)
end

#secretsObject



160
161
162
# File 'lib/nexmo/client.rb', line 160

def secrets
  @secrets ||= Secrets.new(self)
end

#signatureObject



112
113
114
# File 'lib/nexmo/client.rb', line 112

def signature
  @signature ||= Signature.new(self)
end

#smsObject



164
165
166
# File 'lib/nexmo/client.rb', line 164

def sms
  @sms ||= SMS.new(self)
end

#verifyObject



168
169
170
# File 'lib/nexmo/client.rb', line 168

def verify
  @verify ||= Verify.new(self)
end