Class: IcobenchClient
- Inherits:
-
Object
- Object
- IcobenchClient
- Defined in:
- lib/icobench/icobench_client.rb
Constant Summary collapse
- BASE_URL =
'https://icobench.com/api/v1/'
- SSL =
true
Instance Method Summary collapse
- #get_data(url) ⇒ Object
- #icos ⇒ Object
- #icos_filters ⇒ Object
-
#initialize(private_key = nil, public_key = nil, params = {}) ⇒ IcobenchClient
constructor
A new instance of IcobenchClient.
- #people_all ⇒ Object
- #people_expert ⇒ Object
- #people_registered ⇒ Object
- #profile(params) ⇒ Object
- #ratings ⇒ Object
- #stats ⇒ Object
- #trending ⇒ Object
Constructor Details
#initialize(private_key = nil, public_key = nil, params = {}) ⇒ IcobenchClient
Returns a new instance of IcobenchClient.
11 12 13 14 |
# File 'lib/icobench/icobench_client.rb', line 11 def initialize(private_key = nil, public_key = nil, params = {}) @private_key = private_key @public_key = public_key end |
Instance Method Details
#get_data(url) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/icobench/icobench_client.rb', line 66 def get_data(url) uri = URI.parse(url) https = Net::HTTP.new(uri.host, uri.port) if SSL https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE end req = Net::HTTP::Post.new(uri.request_uri) req['X-ICObench-Key'] = @public_key req['X-ICObench-Sig'] = Base64.strict_encode64(OpenSSL::HMAC.digest('sha384', @private_key, '')).force_encoding("utf-8") https.set_debug_output $stderr res = https.request(req) JSON.parse(res.body) end |
#icos ⇒ Object
16 17 18 19 |
# File 'lib/icobench/icobench_client.rb', line 16 def icos url = "#{BASE_URL}icos/all" get_data(url) end |
#icos_filters ⇒ Object
21 22 23 24 |
# File 'lib/icobench/icobench_client.rb', line 21 def icos_filters url = "#{BASE_URL}icos/filters" get_data(url) end |
#people_all ⇒ Object
51 52 53 54 |
# File 'lib/icobench/icobench_client.rb', line 51 def people_all url = "#{BASE_URL}people/all" get_data(url) end |
#people_expert ⇒ Object
56 57 58 59 |
# File 'lib/icobench/icobench_client.rb', line 56 def people_expert url = "#{BASE_URL}people/expert" get_data(url) end |
#people_registered ⇒ Object
61 62 63 64 |
# File 'lib/icobench/icobench_client.rb', line 61 def people_registered url = "#{BASE_URL}people/registered" get_data(url) end |
#profile(params) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/icobench/icobench_client.rb', line 36 def profile(params) if params[:id] url = "#{BASE_URL}ico/#{params[:id]}" get_data(url) elsif params[:url] url = "#{BASE_URL}ico/#{params[:url]}" end get_data(url) end |
#ratings ⇒ Object
31 32 33 34 |
# File 'lib/icobench/icobench_client.rb', line 31 def url = "#{BASE_URL}icos/ratings" get_data(url) end |
#stats ⇒ Object
46 47 48 49 |
# File 'lib/icobench/icobench_client.rb', line 46 def stats url = "#{BASE_URL}other/stats" get_data(url) end |
#trending ⇒ Object
26 27 28 29 |
# File 'lib/icobench/icobench_client.rb', line 26 def trending url = "#{BASE_URL}icos/trending" get_data(url) end |