Class: Apisync::Resource
- Inherits:
-
Object
- Object
- Apisync::Resource
- Defined in:
- lib/apisync/resource.rb
Instance Method Summary collapse
-
#get(conditions) ⇒ Object
Returns all resources that match the conditions passed in.
-
#initialize(name, options = {}) ⇒ Resource
constructor
A new instance of Resource.
-
#save(data) ⇒ Object
Saves a resource.
Constructor Details
#initialize(name, options = {}) ⇒ Resource
Returns a new instance of Resource.
3 4 5 6 |
# File 'lib/apisync/resource.rb', line 3 def initialize(name, = {}) @name = name @options = end |
Instance Method Details
#get(conditions) ⇒ Object
Returns all resources that match the conditions passed in.
-
To find a resource by its id:
get(id: 'customer-id')
-
To find a resource by a column value
get(filters: {column_name: 'customer-id' }})
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/apisync/resource.rb', line 34 def get(conditions) client = Apisync::HttpClient.new( resource_name: @name, options: @options ) client.get( id: conditions[:id], filters: conditions[:filters], headers: conditions[:headers] || {} ) end |
#save(data) ⇒ Object
Saves a resource.
When the resource has an id in ‘data`, a `PUT` request is done. Otherwise a `POST` takes place.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/apisync/resource.rb', line 13 def save(data) data[:type] = @name.to_s.gsub("_", "-") headers = data.delete(:headers) || {} if data[:id].nil? post(data, headers: headers) else put(data, headers: headers) end end |