Class: Outliner::Client
- Inherits:
-
Object
- Object
- Outliner::Client
- Includes:
- HTTParty
- Defined in:
- lib/outliner/client.rb
Instance Method Summary collapse
- #find_or_create_collection(name) ⇒ Object
-
#initialize(base_uri) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method_name, params = {}, options = {}) ⇒ Object
Constructor Details
#initialize(base_uri) ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/outliner/client.rb', line 8 def initialize(base_uri) self.class.base_uri (base_uri + "/api") @token = ENV['OUTLINE_TOKEN'] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, params = {}, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/outliner/client.rb', line 23 def method_missing(method_name, params = {}, = {}) method_name = "/#{method_name.to_s.sub('__', '.')}" = { body: params.to_json, headers: { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => "Outliner/#{Outliner::VERSION}", 'Authorization' => "Bearer #{@token}" }, format: :json, }.merge!() self.class.post(method_name, ) end |
Instance Method Details
#find_or_create_collection(name) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/outliner/client.rb', line 13 def find_or_create_collection(name) collections = self.collections__list(limit: 100)['data'] collections.filter!{|c|c['name'] == name} if collections.size >= 1 collections[0]['id'] else self.collections__create(name: name, description: 'Imported Collection')['data']['id'] end end |