Skip to content

Commit

Permalink
Add verify, lookup and account functions
Browse files Browse the repository at this point in the history
  • Loading branch information
senenh committed Aug 26, 2016
1 parent bd9c3ed commit 7d4ceb6
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 4 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem 'instasent'

## Example
### Send an SMS
You can check 'examples/send-sms.py' file.
You can check 'examples/send-sms.rb' file.
```ruby
require 'instasent'

Expand All @@ -31,9 +31,24 @@ puts response['response_body']
```
## Available functions
```
SMS
client.send_sms(sender, to, text)
client.get_sms(page, per_page)
client.get_sms_by_id(message_id)
VERIFY
client.request_verify(sender, to, text); // text must include %token% string
client.check_verify(id, token)
client.get_verify_by_id(id)
client.get_verify(page, per_page)
LOOKUP
client.do_lookup(to)
client.get_lookup_by_id(id)
client.get_lookups(page, per_page)
ACCOUNT
client.get_account_balance()
```
## Documentation
Complete documentation at :
Expand Down
8 changes: 8 additions & 0 deletions examples/account/get_account_balance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.get_account_balance()

puts response['response_body']
puts response['response_code']
8 changes: 8 additions & 0 deletions examples/lookup/do_lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.do_lookup('+346666666666')

puts response['response_body']
puts response['response_code']
8 changes: 8 additions & 0 deletions examples/lookup/get_lookup_by_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.get_lookup_by_id('id')

puts response['response_body']
puts response['response_code']
8 changes: 8 additions & 0 deletions examples/lookup/get_lookups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.get_lookups(1, 10)

puts response['response_body']
puts response['response_code']
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/verify/check_verify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.check_verify('id', 'token')

puts response['response_body']
puts response['response_code']
8 changes: 8 additions & 0 deletions examples/verify/get_verify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.get_verify(1, 10)

puts response['response_body']
puts response['response_code']
8 changes: 8 additions & 0 deletions examples/verify/get_verify_by_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.get_verify_by_id('id')

puts response['response_body']
puts response['response_code']
8 changes: 8 additions & 0 deletions examples/verify/request_verify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$LOAD_PATH << '.'
require 'instasent'

client = Instasent::Client.new('my-token')
response = client.request_verify('My company', '+346666666666', 'Your code is %token%')

puts response['response_body']
puts response['response_code']
Binary file added instasent-0.1.4.gem
Binary file not shown.
149 changes: 147 additions & 2 deletions lib/instasent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Instasent
class Client

@@rootEndpoint = "http://api.instasent.com/"
@@secureChannel = "https://api.instasent.com/"
@@use_secure_channel = true
@@secureChannel = "https://api.instasent.cdfom/"

This comment has been minimized.

Copy link
@007lva

007lva Sep 11, 2017

Contributor

Typo

@@use_secure_channel = TRUE

def initialize(token, use_secure_channel=true)
@@token = token
Expand Down Expand Up @@ -64,6 +64,149 @@ def get_sms_by_id(id)

end

def send_sms(sender, to, text, client_id='')

if @use_secure_channel
url = @@secureChannel + "sms/"
else
url = @@rootEndpoint + "sms/"
end

http_method = 'POST'

data = {'from' => sender, 'to' => to, 'text' => text}

response = self.execute_request(url, http_method, data)

return response

end

def request_verify(sender, to, text, token_length = '', timeout = '', client_id='')

if @@use_secure_channel
url = @@secureChannel + "verify/"
else
url = @@rootEndpoint + "verify/"
end

http_method = 'POST'
data = {'sms' => {'from' => sender, 'to' => to, 'text' => text}}

# if token_length != ''
# data['tokenLength'] = token_length
# end
#
# if timeout != ''
# data['timeout'] = timeout
# end
#
# if client_id != ''
# data['clientId'] = client_id
# end

response = self.execute_request(url, http_method, data)

return response

end

def check_verify(id, token)

if @@use_secure_channel
url = @@secureChannel + 'verify/' + id + '?token=' + token
else
url = @@rootEndpoint + 'verify/' + id + '?token=' + token
end

http_method = 'GET'

response = self.execute_request(url, http_method, {})

return response

end

def get_verify_by_id(id)

if @@use_secure_channel
url = @@secureChannel + 'verify/' + id
else
url = @@rootEndpoint + 'verify/' + id
end

http_method = 'GET'

response = self.execute_request(url, http_method, {})

return response

end

def get_verify(page=1, per_page=10)

if @use_secure_channel
url = @@secureChannel + 'verify/?page=' + page.to_s + 'per_page=' + per_page.to_s
else
url = @@rootEndpoint + 'verify/?page=' + page.to_s + 'per_page=' + per_page.to_s
end

http_method = 'GET'

response = self.execute_request(url, http_method)

return response

end

def do_lookup(to)

url = if @use_secure_channel then @@secureChannel + 'lookup/' else @@rootEndpoint + 'lookup/' end
http_method = 'POST'
data = {'to' => to}

response = self.execute_request(url, http_method, data)

return response

end

def get_lookup_by_id(id)

url = if @use_secure_channel then @@secureChannel + 'lookup/' + id else @@rootEndpoint + 'lookup/' + id end
http_method = 'GET'
response = self.execute_request(url, http_method, {})

return response

end

def get_lookups(page=1, per_page=10)

if @use_secure_channel
url = @@secureChannel + 'lookup/?page=' + page.to_s + 'per_page=' + per_page.to_s
else
url = @@rootEndpoint + 'lookup/?page=' + page.to_s + 'per_page=' + per_page.to_s
end

http_method = 'GET'

response = self.execute_request(url, http_method)

return response

end

def get_account_balance

url = if @use_secure_channel then @@secureChannel + 'organization/account/' else @@rootEndpoint + 'organization/account/' end
http_method = 'GET'
response = self.execute_request(url, http_method, {})

return response

end

def execute_request(url='', http_method='', data='')

url_parsed = URI.parse(url)
Expand All @@ -76,6 +219,8 @@ def execute_request(url='', http_method='', data='')
end

req.add_field("Authorization", "Bearer "+@@token.to_s)
req.add_field("Accept", "application/json")
req.add_field("Content-Type", "application/json")

res = Net::HTTP.start(url_parsed.host, url_parsed.port) { |http|
http.request(req)
Expand Down
2 changes: 1 addition & 1 deletion lib/instasent/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Instasent
VERSION = "0.1.3"
VERSION = "0.1.4"
end

0 comments on commit 7d4ceb6

Please sign in to comment.