Class: Cyby::Kintone::RestApi
- Inherits:
-
Object
- Object
- Cyby::Kintone::RestApi
- Includes:
- HTTParty
- Defined in:
- lib/cyby/kintone/rest_api.rb
Constant Summary collapse
- AUTH =
'X-Cybozu-Authorization'
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #delete(path, body = {}) ⇒ Object
- #get(path, body = {}) ⇒ Object
- #headers ⇒ Object
-
#initialize(app) ⇒ RestApi
constructor
A new instance of RestApi.
- #post(path, body = {}) ⇒ Object
- #put(path, body = {}) ⇒ Object
Constructor Details
#initialize(app) ⇒ RestApi
Returns a new instance of RestApi.
10 11 12 13 14 15 |
# File 'lib/cyby/kintone/rest_api.rb', line 10 def initialize(app) config = YAML.load_file("#{ENV['HOME']}/.cyby.yml") self.class.base_uri "https://#{config['subdomain']}.cybozu.com/k/v1" @auth = Base64.encode64("#{config['login']}:#{config['password']}").chomp @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
4 5 6 |
# File 'lib/cyby/kintone/rest_api.rb', line 4 def app @app end |
Instance Method Details
#delete(path, body = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cyby/kintone/rest_api.rb', line 54 def delete(path, body = {}) body.merge!(app: @app) = { headers: headers, body: body.to_json } resp = self.class.delete(path, ) if resp.code == 200 resp else fail resp["message"] end end |
#get(path, body = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cyby/kintone/rest_api.rb', line 21 def get(path, body = {}) body.merge!(app: @app) = { headers: headers, body: body.to_json } resp = self.class.get(path, ) if resp.code == 200 resp else fail resp["message"] end end |
#headers ⇒ Object
17 18 19 |
# File 'lib/cyby/kintone/rest_api.rb', line 17 def headers { AUTH => @auth, 'Content-Type' => 'application/json' } end |
#post(path, body = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cyby/kintone/rest_api.rb', line 32 def post(path, body = {}) body.merge!(app: @app) = { headers: headers, body: body.to_json } resp = self.class.post(path, ) if resp.code == 200 resp else fail resp["message"] end end |
#put(path, body = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cyby/kintone/rest_api.rb', line 43 def put(path, body = {}) body.merge!(app: @app) = { headers: headers, body: body.to_json } resp = self.class.put(path, ) if resp.code == 200 resp else fail resp["message"] end end |