Class: IcobenchClient

Inherits:
Object
  • Object
show all
Defined in:
lib/icobench/icobench_client.rb

Constant Summary collapse

BASE_URL =
'https://icobench.com/api/v1/'
SSL =
true

Instance Method Summary collapse

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

#icosObject



16
17
18
19
# File 'lib/icobench/icobench_client.rb', line 16

def icos
  url = "#{BASE_URL}icos/all"
  get_data(url)
end

#icos_filtersObject



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_allObject



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_expertObject



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_registeredObject



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

#ratingsObject



31
32
33
34
# File 'lib/icobench/icobench_client.rb', line 31

def ratings
  url = "#{BASE_URL}icos/ratings"
  get_data(url)
end

#statsObject



46
47
48
49
# File 'lib/icobench/icobench_client.rb', line 46

def stats
  url = "#{BASE_URL}other/stats"
  get_data(url)
end


26
27
28
29
# File 'lib/icobench/icobench_client.rb', line 26

def trending
  url = "#{BASE_URL}icos/trending"
  get_data(url)
end