Module: Everyoneapi

Defined in:
lib/everyoneapi.rb,
lib/everyoneapi/version.rb

Defined Under Namespace

Classes: Person

Constant Summary collapse

API_ENDPOINT =
'https://api.everyoneapi.com'
API_VERSION =
'v1'
VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.person(phone_number, data = nil) ⇒ Object



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

def person(phone_number,data=nil)
   options = {}
   options[:data] = data || "name,address"
   options[:account_sid] = ENV['EVERYONEAPI_SID']
   options[:auth_token] = ENV['EVERYONEAPI_TOKEN']

   url = [API_ENDPOINT, API_VERSION,"phone",phone_number.strip].join("/")
   uri = URI.parse(url)
   uri.query = URI.encode_www_form(options)

   http = Net::HTTP.new(uri.host, uri.port)

   http.use_ssl = true

   request = Net::HTTP::Get.new(uri.request_uri)

   res = http.request(request)

   raise RuntimeError.new res.message unless res.kind_of? Net::HTTPOK
   
   return Person.new  JSON.parse(res.body,:symbolize_names => true)
end