Module: Singly::Endpoint
- Included in:
- Auth::Merge, Auth::Service::Oauth1Apply, Auth::Service::Oauth2Apply, Friends, Friends::Group, Id, Multi, Profile, Profiles, Profiles::Delete, Profiles::DeleteProfile, Profiles::DeleteService, Profiles::Self, Profiles::SelfUpdate, Profiles::Service, Proxy::Delete, Proxy::Get, Proxy::Post, Proxy::Put, Services, Services::Bodymedia, Services::Dropbox, Services::Dwolla, Services::Endpoint, Services::Facebook, Services::Fitbit, Services::Foursquare, Services::Gcal, Services::Gcontacts, Services::Gdocs, Services::Github, Services::Gmail, Services::Google, Services::Gplus, Services::IdEndpoint, Services::Imgur, Services::Instagram, Services::Klout, Services::Linkedin, Services::Meetup, Services::Paypal, Services::Picasa, Services::Rdio, Services::Reddit, Services::Runkeeper, Services::Shutterfly, Services::Soundcloud, Services::Stocktwits, Services::ThirtySevenSignals, Services::Tout, Services::Tumblr, Services::Twitter, Services::Withings, Services::Wordpress, Services::Yammer, Services::Youtube, Services::Zeo, Types, Types::Type
- Defined in:
- lib/singly/endpoint.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#fetch(opts = {}) ⇒ Object
The opts argument is for Typhoeus overrides.
- #initialize(params = {}) ⇒ Object
-
#url ⇒ Object
String representation of the composed endpoint.
-
#validate ⇒ Object
Raises an error if any required parameters have not been supplied or if any path components are missing.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/singly/endpoint.rb', line 12 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/singly/endpoint.rb', line 11 def path @path end |
Instance Method Details
#fetch(opts = {}) ⇒ Object
The opts argument is for Typhoeus overrides
20 21 22 23 |
# File 'lib/singly/endpoint.rb', line 20 def fetch(opts={}) validate Singly::Http.fetch(path, .merge(opts)) end |
#initialize(params = {}) ⇒ Object
14 15 16 17 |
# File 'lib/singly/endpoint.rb', line 14 def initialize(params={}) init_path(params) (params) end |
#url ⇒ Object
String representation of the composed endpoint. Parameter order is deterministic so it can be used as a key in the /multi endpoint.
37 38 39 40 41 42 43 44 45 |
# File 'lib/singly/endpoint.rb', line 37 def url validate query_string = [:params].sort.inject([]) do |queries, param| queries << ("#{CGI.escape(param[0].to_s)}=#{CGI.escape(param[1].to_s)}") end.join("&") url = "#{Singly::Http.base_url}#{path}" url += "?#{query_string}" unless query_string.empty? url end |
#validate ⇒ Object
Raises an error if any required parameters have not been supplied or if any path components are missing.
27 28 29 30 31 32 |
# File 'lib/singly/endpoint.rb', line 27 def validate Singly::Error.y_u_no?("has all route params: #{path}") { path.include? ":" } = self.class.required_params - [:params].keys Singly::Error.y_u_no?("has required params :#{missing_options.join(', :')}") { .any? } true end |