Class: Brio::Client

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/brio/client.rb

Constant Summary collapse

HTTP_VERBS =
{ 
  create: 'post', 
  delete: 'delete', 
  get: 'get' 
}
METHOD_PATTERNS =
{
  users: /(.*)_user(_?(.*))/,
  posts: /(.*)_post(_?(.*))/
}

Constants included from API

API::CLIENT_ID, API::DEFAULT_API_HOST, API::DEFAULT_OAUTH_HOST, API::DEFAULT_PROTOCOL, API::REDIRECT_URI, API::RESPONSE_TYPE, API::SCOPE

Instance Method Summary collapse

Methods included from API

#oauth_url, #posts_url, #users_url

Constructor Details

#initializeClient

Returns a new instance of Client.



21
22
23
24
25
26
27
28
29
# File 'lib/brio/client.rb', line 21

def initialize
  @conn = Faraday.new( :url => base_api_url ) do |faraday|
    faraday.request  :json
    faraday.response :json, :content_type => /\bjson$/
    faraday.adapter  Faraday.default_adapter
  end
  @rc = RCFile.instance
  add_oauth_header unless @rc.empty?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/brio/client.rb', line 35

def method_missing(method_name, *args, &block)
  case 
  when method_name.to_s =~ METHOD_PATTERNS[:users]
    users HTTP_VERBS[$1.to_sym], args, $3.gsub(/_/, '/')
  when method_name.to_s =~ METHOD_PATTERNS[:posts]
    posts HTTP_VERBS[$1.to_sym], args, $3.gsub(/_/, '/')
  else
    super
  end 
end

Instance Method Details

#configObject



31
32
33
# File 'lib/brio/client.rb', line 31

def config
  @rc
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/brio/client.rb', line 46

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s =~ METHOD_PATTERNS[:users] ||
  method_name.to_s =~ METHOD_PATTERNS[:posts]
end