Method: Frodo::Concerns::API#query

Defined in:
lib/frodo/concerns/api.rb

#query(query) ⇒ Object

Public: Execute a query and returns the result.

Query can be the url_chunk per the OData V4 spec or a Frodo::Query. The latter being preferred

Examples

# Find the names of all Accounts
client.query("leads?$filter=firstname eq 'yo'")

or

query = client.service['leads'].query
query.where("firstname eq 'yo'")
client.query(query)

Returns a list of Frodo::Entity



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/frodo/concerns/api.rb', line 64

def query(query)
  url_chunk, entity_set = if query.is_a?(Frodo::Query)
                [query.to_s, query.entity_set.name]
              else
                [query]
              end

  body = api_get(url_chunk).body
  # if manual query as a string we detect the set on the response
  entity_set = body['@odata.context'].split('#')[-1] if entity_set.nil?

  build_entity(entity_set, body)
end