class Basecampeverest::Connect
Attributes
base_uri[RW]
Set a few variables
basecamp_id[RW]
Set a few variables
headers[RW]
Set a few variables
user_agent[RW]
Set a few variables
Public Class Methods
new(basecamp_id, authorization, user_agent)
click to toggle source
Initializes the connection to Basecamp using httparty.
@param basecamp_id
[String] the Basecamp company ID @param authorization [Hash] authorization hash consisting of a username and password combination (:username, :password) or an access_token (:access_token) @param user_agent
[String] the user-agent string to include in header of requests
# File lib/basecampeverest/connect.rb, line 70 def initialize(basecamp_id, authorization, user_agent) # Set some variables self.class.base_uri "https://basecamp.com/#{basecamp_id}/api/v1" self.class.headers 'User-Agent' => user_agent self.auth = authorization # end method end
Public Instance Methods
auth=(authorization)
click to toggle source
Sets the authorization information. Need to
@param authorization [Hash] authorization hash consisting of a username and password combination (:username, :password) or an access_token (:access_token)
# File lib/basecampeverest/connect.rb, line 83 def auth=(authorization) clensed_auth_hash = {} authorization.each {|k, v| clensed_auth_hash[k.to_sym] = v } # nice and pretty now authorization = clensed_auth_hash if authorization.has_key? :access_token # clear the basic_auth, if it's set self.class.default_options.reject!{ |k| k == :basic_auth } # set the Authorization headers self.class.headers.merge!("Authorization" => "Bearer #{authorization[:access_token]}") elsif authorization.has_key?(:username) && authorization.has_key?(:password) # ... then we pass it off to basic auth self.class.basic_auth authorization[:username], authorization[:password] # check if the user tried passing in some other stupid stuff. # this should never be the case if the user follows instructions. self.class.headers.reject!{ |k, v| k == "Authorization" } else # something inportant is missing if we get here. raise "Incomplete Authorization hash. Please check the Authentication Hash." #end else end # end method end