Module: FsApi::Service::Searchable

Included in:
Client, Invoice, Product
Defined in:
lib/fs_api/service/searchable.rb

Instance Method Summary collapse

Instance Method Details

#search(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fs_api/service/searchable.rb', line 4

def search(options)
  if options.is_a? String
    field = 'all'
    value = options
  elsif options.is_a? Hash
    field, value = options.first
  end

  search_path = ["search#{path}", field, value].join('/')

  if response = api_client.get(search_path)
    if response.code.to_i == success_status_code
      JSON.parse(response.body).map do |attributes|
        collection_class.new(attributes.merge(from_api: true))
      end
    end
  end
end