Module: Freshbooks::API::CRUD

Included in:
Client
Defined in:
lib/freshbooks/api/crud.rb

Overview

Methods for CRUD in [Freshbooks::Client].

Instance Method Summary collapse

Instance Method Details

#create(params = {}) ⇒ Object

Creates something based on params.

Examples:

Create a new project.

@clients.projects.create(name: "Some Project", bill_method: "project-rate")
# => { "project_id" => "1234" }

Parameters:

  • params (Hash) (defaults to: {})

    A hash of params to create something.


12
13
14
# File 'lib/freshbooks/api/crud.rb', line 12

def create(params = {})
  call("#{@endpoint}.create", { @endpoint => params })
end

#delete(params = {}) ⇒ Object

Delete something based on its `<something>_id`.

Examples:

Delete a project.

@client.projects.delete(project_id: 1234)
# => 200 OK

Parameters:

  • params (Hash) (defaults to: {})

    A hash of params to delete something.


45
46
47
# File 'lib/freshbooks/api/crud.rb', line 45

def delete(params = {})
  call("#{@endpoint}.delete", params)
end

#get(params = {}) ⇒ Object

Get something's details based on the `<something>_id`.

Examples:

Get a project by `project_id`.

@client.projects.get(project_id: 1234)
# => {"projects" => [...]}

Parameters:

  • params (Hash) (defaults to: {})

    A hash of params to get something's details.


34
35
36
# File 'lib/freshbooks/api/crud.rb', line 34

def get(params = {})
  call("#{@endpoint}.get", params)
end

#list(params = {}) ⇒ Object

List a bunch of somethings.

Examples:

List all projects.

@client.projects.list
# => {"projects" => [...]}

Parameters:

  • params (Hash) (defaults to: {})

    A hash of params ot filter the listing.


56
57
58
# File 'lib/freshbooks/api/crud.rb', line 56

def list(params = {})
  call("#{@endpoint}.list", params)
end

#update(params = {}) ⇒ Object

Updates something based on params.

Examples:

Update an existing project.

@client.projects.update(project_id: 1234, bill_method: "credit-card")
# => { "project_id" => "1234" }

Parameters:

  • params (Hash) (defaults to: {})

    A hash of params to update something.


23
24
25
# File 'lib/freshbooks/api/crud.rb', line 23

def update(params = {})
  call("#{@endpoint}.update", { @endpoint => params })
end