Class: Basecampeverest::Connect
- Inherits:
-
Object
- Object
- Basecampeverest::Connect
- Includes:
- HTTParty, JSON
- Defined in:
- lib/basecampeverest/connect.rb
Instance Attribute Summary collapse
-
#authorization ⇒ Object
Set a few variables.
-
#base_uri ⇒ Object
Set a few variables.
-
#basecamp_id ⇒ Object
Set a few variables.
-
#headers ⇒ Object
Set a few variables.
-
#user_agent ⇒ Object
Set a few variables.
Instance Method Summary collapse
-
#auth=(authorization) ⇒ Object
Sets the authorization information.
-
#initialize(basecamp_id, authorization, user_agent) ⇒ Connect
constructor
Initializes the connection to Basecamp using httparty.
Constructor Details
#initialize(basecamp_id, authorization, user_agent) ⇒ Connect
Initializes the connection to Basecamp using httparty.
70 71 72 73 74 75 76 77 |
# File 'lib/basecampeverest/connect.rb', line 70 def initialize(basecamp_id, , 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 = # end method end |
Instance Attribute Details
#authorization ⇒ Object
Set a few variables
63 64 65 |
# File 'lib/basecampeverest/connect.rb', line 63 def @authorization end |
#base_uri ⇒ Object
Set a few variables
63 64 65 |
# File 'lib/basecampeverest/connect.rb', line 63 def base_uri @base_uri end |
#basecamp_id ⇒ Object
Set a few variables
63 64 65 |
# File 'lib/basecampeverest/connect.rb', line 63 def basecamp_id @basecamp_id end |
#headers ⇒ Object
Set a few variables
63 64 65 |
# File 'lib/basecampeverest/connect.rb', line 63 def headers @headers end |
#user_agent ⇒ Object
Set a few variables
63 64 65 |
# File 'lib/basecampeverest/connect.rb', line 63 def user_agent @user_agent end |
Instance Method Details
#auth=(authorization) ⇒ Object
Sets the authorization information. Need to
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/basecampeverest/connect.rb', line 83 def auth=() clensed_auth_hash = {} .each {|k, v| clensed_auth_hash[k.to_sym] = v } # nice and pretty now = clensed_auth_hash if .has_key? :access_token # clear the basic_auth, if it's set self.class..reject!{ |k| k == :basic_auth } # set the Authorization headers self.class.headers.merge!("Authorization" => "Bearer #{[:access_token]}") elsif .has_key?(:username) && .has_key?(:password) # ... then we pass it off to basic auth self.class.basic_auth [:username], [: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 |