Class: Ruzbx::Entity
- Inherits:
-
Object
- Object
- Ruzbx::Entity
- Defined in:
- lib/ruzbx/entity.rb
Overview
TODO
Class Method Summary collapse
Instance Method Summary collapse
- #commit ⇒ Object
- #data(data = {}) ⇒ Object
- #headers(headers) ⇒ Object
-
#initialize ⇒ Entity
constructor
A new instance of Entity.
- #method(method) ⇒ Object
- #no_auth ⇒ Object
- #params(params) ⇒ Object
- #path(path = 'api_jsonrpc.php') ⇒ Object
- #rpc_method(method) ⇒ Object
Constructor Details
#initialize ⇒ Entity
Returns a new instance of Entity.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruzbx/entity.rb', line 6 def initialize @token = Configuration.token @method = :POST @rpc_method = nil @params = {} @headers = { 'Content-Type': 'application/json' } @data = { "jsonrpc": '2.0', "id": rand(1000) } @auth = { 'Authorization': "Bearer #{@token}" } @rest_api = nil end |
Class Method Details
.build(&block) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ruzbx/entity.rb', line 17 def self.build(&block) entity = new return entity unless block_given? entity.instance_eval(&block) entity end |
Instance Method Details
#commit ⇒ Object
62 63 64 65 66 67 |
# File 'lib/ruzbx/entity.rb', line 62 def commit case @method when :POST post.body end end |
#data(data = {}) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/ruzbx/entity.rb', line 54 def data(data = {}) @data.merge!(data) return @data if @data raise ArgumentError, "No argument to 'data' was given." end |
#headers(headers) ⇒ Object
34 35 36 |
# File 'lib/ruzbx/entity.rb', line 34 def headers(headers) @headers = headers end |
#method(method) ⇒ Object
38 39 40 |
# File 'lib/ruzbx/entity.rb', line 38 def method(method) @method = method end |
#no_auth ⇒ Object
26 27 28 |
# File 'lib/ruzbx/entity.rb', line 26 def no_auth @auth = {} end |
#params(params) ⇒ Object
30 31 32 |
# File 'lib/ruzbx/entity.rb', line 30 def params(params) @params = params end |
#path(path = 'api_jsonrpc.php') ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ruzbx/entity.rb', line 42 def path(path = 'api_jsonrpc.php') @path ||= "#{@rest_api}/#{path}" return @path if @path raise ArgumentError, "No argument to 'path' was given." end |
#rpc_method(method) ⇒ Object
50 51 52 |
# File 'lib/ruzbx/entity.rb', line 50 def rpc_method(method) @rpc_method = { method: method } end |