Class: Behance::Client

Inherits:
Object
  • Object
show all
Includes:
Collections, CreativesToFollow, Fields, Project, User, Wips
Defined in:
lib/behance/user.rb,
lib/behance/wips.rb,
lib/behance/client.rb,
lib/behance/fields.rb,
lib/behance/project.rb,
lib/behance/collections.rb,
lib/behance/creatives_to_follow.rb

Defined Under Namespace

Modules: Collections, CreativesToFollow, Fields, Project, User, Wips

Constant Summary collapse

API_URL =
"http://www.behance.net/v2/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CreativesToFollow

#creatives_to_follow

Methods included from Fields

#fields, #popular

Methods included from Collections

#collection, #collection_projects, #collections

Methods included from Wips

#wip, #wip_revision, #wip_revision_comments, #wips

Methods included from User

#user, #user_appreciations, #user_collections, #user_followers, #user_following, #user_projects, #user_stats, #user_wips, #user_work_experience, #users

Methods included from Project

#project, #project_comments, #projects

Constructor Details

#initialize(options = {}) ⇒ Client

Public: Initialize a client for API requests.

options - The Hash with options required by Behance:

:access_token - Behance API token.

Examples

@client = Behance::Client.new(access_token: "aKlie12MCJa5")

Returns a Faraday instance object.



36
37
38
39
40
41
42
# File 'lib/behance/client.rb', line 36

def initialize(options={})
  @access_token = options[:access_token]
  @connection = Faraday.new(url: Behance::Client::API_URL) do |b|
    b.adapter Faraday.default_adapter
    b.use     FaradayMiddleware::ParseJson
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



24
25
26
# File 'lib/behance/client.rb', line 24

def access_token
  @access_token
end

#connectionObject

Returns the value of attribute connection.



24
25
26
# File 'lib/behance/client.rb', line 24

def connection
  @connection
end

Instance Method Details

#request(path, options = {}) ⇒ Object

Public: Makes a http request to the API.

path - A String that represents the endpoint path. options - Hash of parameters to pass along.

Examples

request("users/1")
request("projects", page: 2)

Returns a response body from the API.



55
56
57
58
59
60
61
62
63
64
# File 'lib/behance/client.rb', line 55

def request(path, options={})
  response = @connection.get do |req|
    req.url path
    req.params[:api_key] = @access_token
    options.each do |key, val|
      req.params[key] = val
    end
  end
  response.body
end