Class: Terracycle::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/terracycle/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/terracycle/base.rb', line 9

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/terracycle/base.rb', line 7

def client
  @client
end

Instance Method Details

#brigade(id, format) ⇒ Array

Terracycle.brigade_lists(“chip bag brigade”, “energy bar wrapper brigade”)

Examples:

Return the brigade minimum waste collected


Parameters:

  • brigade_id (Integer, String)

    The id or slug of the brigade.

  • options (Hash)

    a customizable set of options

Returns:

  • (Array)

See Also:



91
92
93
# File 'lib/terracycle/base.rb', line 91

def brigade(id, format)
  perform_get("/brigades/#{id}.#{format}", :mash => true)
end

#collection_create(body = {}) ⇒ Object

Note:

Brigade sign up is unlimited.

Brigade/collection sign up

Terracycle.brigade_lists(“chip bag brigade”, “energy bar wrapper brigade”)

Parameters:

  • brigade_id (Integer, String)

    The id or slug of the brigade.

  • id (Integer)

    The user id of the brigade.

See Also:



133
134
135
136
# File 'lib/terracycle/base.rb', line 133

def collection_create(body = {})

  perform_post("/collections/create.json", :body => body)
end

#label_requests_show(id, format) ⇒ Array

Returns The subscribers of the specified collection.

Examples:

Return the label request of user

Terracycle.collection("chip bag", "Toasted chip")

Parameters:

  • id (Integer)

    The collection id of the Label Requests

  • options (Hash)

    A customizable set of options.

Returns:

  • (Array)

    The subscribers of the specified collection.

See Also:



105
106
107
# File 'lib/terracycle/base.rb', line 105

def label_requests_show(id, format)
  perform_get("/label_requests/#{id}.#{format}", :mash => true)  
end

#label_show(id, format) ⇒ Array

Returns the subscribers of the specified labels

Examples:

Return the labels of user

Terracycle.collection("chip bag", "Toasted chip")

Parameters:

  • id (Integer)

    The collection id of the label.

  • options (Hash)

    A customizable set of options.

Returns:

  • (Array)

    The subscribers of the specified collection.

See Also:



119
120
121
# File 'lib/terracycle/base.rb', line 119

def label_show(id, format)
  perform_get("/labels/#{id}.#{format}")  
end

#signup_create(user, email, first_mame, last_name, login, default_charity, password, password_confirmation, minimum_registration_age, terms) ⇒ Object

Signs up a new user

One of the following must be present: first name, last name - see api.terracycle.net/api_home/sign_up for complete list

Examples:

Update the authenticating user’s profile


See Also:



22
23
24
25
26
# File 'lib/terracycle/base.rb', line 22

def (user, email, first_mame, last_name, , default_charity, password, password_confirmation, minimum_registration_age, terms)
  perform_post("/users/create.json", :body => {:user => user, :email => email, :first_mame => first_mame, :last_name => last_name, :login => ,
              :default_charity => default_charity, :password => password, :password_confirmation => password_confirmation, 
              :minimum_registration_age => minimum_registration_age, :terms => terms })
end

#update_user(username, body = {}) ⇒ Object

Note:

This method asynchronously processes the uploaded file before updating the user’s profile.

Updates the authenticating user’s profile

One of the following must be present: first name, last name - see api.Terracycle.net/api_home/update_use for complete list

Examples:

Update the authenticating user’s profile


See Also:



52
53
54
# File 'lib/terracycle/base.rb', line 52

def update_user(username, body={})
  perform_post("/users/update/#{username}.json", :body => body)
end

#collections(options = {}) ⇒ Hashie::Mash #collections(user, options = {}) ⇒ Hashie::Mash

Returns a user’s collection

Overloads:

  • #collections(options = {}) ⇒ Hashie::Mash

    Examples:

    Return the authenticated user’s collections

    Terracycle.collections
    

    Parameters:

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

      A customizable set of options.

    Options Hash (options):

    • :cursor (Integer) — default: -1

      Breaks the results into pages. Provide values as returned in the response objects’s next_cursor and previous_cursor attributes to page back and forth in the list.

    Returns:

    • (Hashie::Mash)
  • #collections(user, options = {}) ⇒ Hashie::Mash

    Examples:

    Return @johndoe33’s collections

    Terracycle.collections("johndoe33")
    Terracycle.collections(7505382)  # Same as above
    

    Parameters:

    • user (Integer, String)

      A Terracycle user ID or user name.

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

      A customizable set of options.

    Options Hash (options):

    • :cursor (Integer) — default: -1

      Breaks the results into pages. Provide values as returned in the response objects’s next_cursor and previous_cursor attributes to page back and forth in the list.

    Returns:

    • (Hashie::Mash)

See Also:



77
78
79
# File 'lib/terracycle/base.rb', line 77

def user_collection(username, id, format)
   perform_get("/users/#{username}/collections/#{id}.#{format}",  :mash => false)
end

#user_info(username, format) ⇒ Object

TODO:

Overload the method to allow fetching of the authenticated user’s user name from configuration.

Returns extended information of a given user

Examples:

Return extended information

Terracycle.user("Johndoe33")
Terracycle.user(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Terracycle user ID or user name.

See Also:



38
39
40
# File 'lib/terracycle/base.rb', line 38

def (username, format)
  perform_get("/users/#{username}.#{format}",  :mash => false)
end