Class: Impas::Client
- Inherits:
-
Object
- Object
- Impas::Client
- Defined in:
- lib/impas-client.rb,
lib/impas-client/version.rb
Constant Summary collapse
- VERSION =
"0.0.10"- API_URL =
"http://impas-hideack.sqale.jp/"
Instance Attribute Summary collapse
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#op_key ⇒ Object
Returns the value of attribute op_key.
Instance Method Summary collapse
- #add_group(group_name) ⇒ Object
- #add_url(grp_key, url, user = nil) ⇒ Object
- #delete_group(grp_key) ⇒ Object
- #groups ⇒ Object
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #ranking(grp_key, type = "all", limit = 10) ⇒ Object
- #recommend(grp_key, visitor, limit = 10) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/impas-client.rb', line 9 def initialize(args ={}) @api_url = (args[:api_url].nil?) ? API_URL : args[:api_url] @op_key = args[:op_key] @@conn = Faraday.new(:url => @api_url) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end |
Instance Attribute Details
#api_url ⇒ Object
Returns the value of attribute api_url.
7 8 9 |
# File 'lib/impas-client.rb', line 7 def api_url @api_url end |
#op_key ⇒ Object
Returns the value of attribute op_key.
7 8 9 |
# File 'lib/impas-client.rb', line 7 def op_key @op_key end |
Instance Method Details
#add_group(group_name) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/impas-client.rb', line 20 def add_group(group_name) entry_point = "/api/group/#{@op_key}" res = @@conn.post do |req| req.url entry_point req.headers['Content-Type'] = 'application/json' req.body = "{\"name\":\"#{group_name}\"}" end if res.status == 200 desc = JSON.parse(res.body) if desc["result"] != "ok" raise StandardError.new("Process error. message:#{desc['explain']}") end else raise StandardError.new("HTTP status:#{res.status}") end true end |
#add_url(grp_key, url, user = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/impas-client.rb', line 65 def add_url(grp_key, url, user = nil) entry_point = "/api/registration/#{grp_key}" res = @@conn.post do |req| req.url entry_point req.headers['Content-Type'] = 'application/json' if user.nil? req.body = "{\"url\":\"#{url}\"}" else req.body = "{\"url\":\"#{url}\", \"user\":\"#{user}\"}" end end if res.status == 200 desc = JSON.parse(res.body) if desc["result"] != "ok" raise StandardError.new("Process error. message:#{desc['explain']}") end else raise StandardError.new("HTTP status:#{res.status}") end true end |
#delete_group(grp_key) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/impas-client.rb', line 42 def delete_group(grp_key) entry_point = "/api/group/#{@op_key}/#{grp_key}" res = @@conn.delete entry_point if res.status != 200 raise StandardError.new("HTTP status:#{res.status}") end true end |
#groups ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/impas-client.rb', line 53 def groups entry_point = "/api/group/#{@op_key}" res = @@conn.get entry_point if res.status != 200 raise StandardError.new("HTTP status:#{res.status}") end desc = JSON.parse(res.body) desc["description"]["groups"] end |
#ranking(grp_key, type = "all", limit = 10) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/impas-client.rb', line 93 def ranking(grp_key, type = "all", limit = 10) entry_point = "/api/ranking/#{grp_key}/#{type}/#{limit}" res = @@conn.get entry_point if res.status != 200 raise StandardError.new("HTTP status:#{res.status}") end desc = JSON.parse(res.body) desc["description"]["ranking"] end |
#recommend(grp_key, visitor, limit = 10) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/impas-client.rb', line 105 def recommend(grp_key, visitor, limit=10) entry_point = "/api/recommend/#{grp_key}/#{visitor}/#{limit}" res = @@conn.get entry_point if res.status == 200 desc = JSON.parse(res.body) if desc["result"] != "ok" raise StandardError.new("Process error. message:#{desc['explain']}") end else raise StandardError.new("HTTP status:#{res.status}") end desc = JSON.parse(res.body) desc["description"]["recommends"] end |