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 = {}) ⇒ 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 = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/outliner/client.rb', line 23 def method_missing(method_name, params = {}) method_name = '/' + method_name.to_s.sub('_', '.') body = {token: @token}.merge(params).to_json = { body: body, headers: { 'Accept'=>'application/json', 'Content-Type': 'application/json', 'User-Agent': "Outliner/#{Outliner::VERSION}" }, format: :json } 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 |