Class: Freemle::Client::Resource

Inherits:
Struct
  • Object
show all
Defined in:
lib/freemle/client/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config

Returns:

  • (Object)

    the current value of config



5
6
7
# File 'lib/freemle/client/resource.rb', line 5

def config
  @config
end

#pluralObject

Returns the value of attribute plural

Returns:

  • (Object)

    the current value of plural



5
6
7
# File 'lib/freemle/client/resource.rb', line 5

def plural
  @plural
end

#singularObject

Returns the value of attribute singular

Returns:

  • (Object)

    the current value of singular



5
6
7
# File 'lib/freemle/client/resource.rb', line 5

def singular
  @singular
end

Instance Method Details

#create(payload, &block) ⇒ Hash

Persists a resource on freemle.com, given a payload.

Examples:

customers.create(
  company_name: "Zilverline B.V.",
  address: {
    street: "Cruquiusweg 109 F",
    postal_code: "1019 AG",
    city: "Amsterdam",
    country_code: "NL"
  }
)
customers.create(
  company_name: "Zilverline B.V.",
  address: {
    street: "Cruquiusweg 109 F",
    postal_code: "1019 AG",
    city: "Amsterdam",
    country_code: "NL"
  }
) do |response|
  # Roll your own response handler
end

Parameters:

  • payload (Hash)

    A hash containing the fields to set.

  • block (Proc)

    A custom response handler.

Returns:

  • (Hash)

    By default, a JSON parsed response body.

Since:

  • 1.0.0



60
61
62
63
# File 'lib/freemle/client/resource.rb', line 60

def create(payload, &block)
  block = default_handler unless block_given?
  request.post(json.generate({singular => payload}), &block)
end

#search(query, &block) ⇒ Array<Hash>

Performs a search on this resource, given a query.

Examples:

customers.search('Zilverline')
customers.search('Zilverline') do |response|
  # Roll your own response handler
end

Parameters:

  • query (Hash)

    A hash containing the fields to search for.

  • block (Proc)

    A custom response handler.

Returns:

  • (Array<Hash>)

    By default, a JSON parsed response body.

Since:

  • 1.0.0



23
24
25
26
# File 'lib/freemle/client/resource.rb', line 23

def search(query, &block)
  block = default_handler unless block_given?
  request.get(params: {query: query}, &block)
end