Class: DiographStore::DiographApiRequest
- Inherits:
-
Object
- Object
- DiographStore::DiographApiRequest
- Defined in:
- lib/diograph_store/diograph_api_request.rb
Instance Method Summary collapse
- #body(diory_hash) ⇒ Object
- #endpoint ⇒ Object
-
#headers ⇒ Object
private.
-
#initialize(type, args) ⇒ DiographApiRequest
constructor
A new instance of DiographApiRequest.
- #options ⇒ Object
Constructor Details
#initialize(type, args) ⇒ DiographApiRequest
5 6 7 8 9 10 11 12 13 |
# File 'lib/diograph_store/diograph_api_request.rb', line 5 def initialize(type, args) if ENV["DIOGRAPH_STORE_HOST"].nil? || ENV["DIOGRAPH_STORE_TOKEN"].nil? raise "DIOGRAPH_STORE_HOST or DIOGRAPH_STORE_TOKEN environmental variables not defined" end @host = ENV["DIOGRAPH_STORE_HOST"] @token = ENV["DIOGRAPH_STORE_TOKEN"] @diory_hash = args end |
Instance Method Details
#body(diory_hash) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/diograph_store/diograph_api_request.rb', line 35 def body(diory_hash) { "data" => { "type" => "diories", "attributes" => diory_hash } }.to_json end |
#endpoint ⇒ Object
15 16 17 |
# File 'lib/diograph_store/diograph_api_request.rb', line 15 def endpoint "#{@host}/v1/diories" end |
#headers ⇒ Object
private
28 29 30 31 32 33 |
# File 'lib/diograph_store/diograph_api_request.rb', line 28 def headers { "Content-Type" => "application/vnd.api+json", "Authorization" => @token } end |
#options ⇒ Object
19 20 21 22 23 24 |
# File 'lib/diograph_store/diograph_api_request.rb', line 19 def { headers: headers, body: body(@diory_hash) } end |