Class: Kankankan::APIClient
- Inherits:
-
Object
- Object
- Kankankan::APIClient
- Defined in:
- lib/kankankan.rb
Overview
GET/POST client
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(base_url) ⇒ APIClient
constructor
A new instance of APIClient.
-
#send_get(uri) ⇒ Object
Send Get.
-
#send_post(uri, data) ⇒ Object
Send POST.
Constructor Details
#initialize(base_url) ⇒ APIClient
Returns a new instance of APIClient.
17 18 19 20 |
# File 'lib/kankankan.rb', line 17 def initialize(base_url) base_url += '/' unless base_url.match(/\/$/) @url = base_url + 'index.php?/api/v2/' end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
15 16 17 |
# File 'lib/kankankan.rb', line 15 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
14 15 16 |
# File 'lib/kankankan.rb', line 14 def user @user end |
Instance Method Details
#send_get(uri) ⇒ Object
Send Get
Issues a GET request (read) against the API and returns the result (as Ruby hash).
Arguments:
uri The API method to call including parameters
(e.g. get_case/1)
33 34 35 |
# File 'lib/kankankan.rb', line 33 def send_get(uri) _send_request('GET', uri, nil) end |
#send_post(uri, data) ⇒ Object
Send POST
Issues a POST request (write) against the API and returns the result (as Ruby hash).
Arguments:
uri The API method to call including parameters
(e.g. add_case/1)
data The data to submit as part of the request (as
Ruby hash, strings must be UTF-8 encoded)
50 51 52 |
# File 'lib/kankankan.rb', line 50 def send_post(uri, data) _send_request('POST', uri, data) end |