Class: Brio::Client
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
- #config ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Methods included from API
#oauth_url, #posts_url, #users_url
Constructor Details
#initialize ⇒ Client
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
#config ⇒ Object
31 32 33 |
# File 'lib/brio/client.rb', line 31 def config @rc end |
#respond_to_missing?(method_name, include_private = false) ⇒ 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 |