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
# 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.logger = options[:logger] || (defined?(Rails.logger) && Rails.logger)
end

Instance Attribute Details

#api_keyObject



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

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



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

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



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/nexmo/client.rb', line 80

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

#private_keyObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/nexmo/client.rb', line 92

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



69
70
71
72
73
74
75
76
77
78
# File 'lib/nexmo/client.rb', line 69

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



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

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



108
109
110
# File 'lib/nexmo/client.rb', line 108

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

#alertsObject



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

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

#applicationsObject



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

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

#auth_token=(auth_token) ⇒ Object



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

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

  @token = auth_token
end

#callsObject



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

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

#conversionsObject



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

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

#filesObject



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

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

#loggerObject



31
32
33
# File 'lib/nexmo/client.rb', line 31

def logger
  @logger
end

#logger=(logger) ⇒ Object



35
36
37
# File 'lib/nexmo/client.rb', line 35

def logger=(logger)
  @logger = Nexmo::KeyValueLogger.new(logger)
end

#messagesObject



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

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

#number_insightObject



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

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

#numbersObject



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

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

#pricingObject



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

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

#redactObject



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

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

#signatureObject



104
105
106
# File 'lib/nexmo/client.rb', line 104

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

#smsObject



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

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

#verifyObject



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

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