-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiconnect_restclient.rb
More file actions
32 lines (28 loc) · 947 Bytes
/
apiconnect_restclient.rb
File metadata and controls
32 lines (28 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'rubygems'
require 'rest_client'
require 'digest/md5'
require 'json'
# require 'will_paginate/array'
class MoreApiConnect
def initialize
@public_key = 'XXXXXXX'
@private_key = 'XXXXXXX'
@base_url = 'http://testing.tesing.com'
end
def get_char_info(resource)
params = authentication
url_params = { resource: resource, ts: params[:ts], apikey: params[:apikey], hash: params[:hash] }
response = RestClient.get(restruction_url(url_params))
char_data = JSON.parse(response)['data']['results']
end
def authentication
timestamp = Time.now.to_i.to_s
oauth_hash = Digest::MD5.hexdigest(timestamp+@private_key+@public_key)
{ ts: timestamp, apikey: @public_key, hash: oauth_hash }
end
def restruction_url(params)
"#{@base_url}#{params[:resource]}?ts=#{params[:ts]}&apikey=#{params[:apikey]}&hash=#{params[:hash]}"
end
end
api = MoreApiConnect.new
api.get_char_info('/v1/public/comics')