Class: OctocatHerder::Connection
- Inherits:
-
Object
- Object
- OctocatHerder::Connection
- Includes:
- HTTParty
- Defined in:
- lib/octocat_herder/connection.rb
Instance Attribute Summary collapse
-
#oauth2_token ⇒ Object
readonly
Returns the value of attribute oauth2_token.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
Instance Method Summary collapse
- #get(end_point, options = {}) ⇒ Object
- #httparty_options ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/octocat_herder/connection.rb', line 15 def initialize(={}) raise ArgumentError.new( "OctocatHerder::Connection does not accept: #{.class}" ) unless .is_a? Hash .keys.each do |k| raise ArgumentError.new("Unknown option: '#{k}'") unless [ :user_name, :password, :oauth2_token ].include? k end if .keys.include?(:user_name) or .keys.include?(:password) raise ArgumentError.new("When providing :user_name or :password, both are required") unless .keys.include?(:user_name) and .keys.include?(:password) end if .keys.include?(:oauth2_token) and .keys.include?(:user_name) raise ArgumentError.new('Cannot provide both an OAuth2 Token, and a user name and password') end @user_name = [:user_name] @password = [:password] @oauth2_token = [:oauth2_token] if oauth2_token @httparty_options = { :headers => { 'Authorization' => "token #{oauth2_token}" } } elsif user_name @httparty_options = { :basic_auth => { :username => user_name, :password => password } } end end |
Instance Attribute Details
#oauth2_token ⇒ Object (readonly)
Returns the value of attribute oauth2_token.
9 10 11 |
# File 'lib/octocat_herder/connection.rb', line 9 def oauth2_token @oauth2_token end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/octocat_herder/connection.rb', line 9 def password @password end |
#user_name ⇒ Object (readonly)
Returns the value of attribute user_name.
9 10 11 |
# File 'lib/octocat_herder/connection.rb', line 9 def user_name @user_name end |
Instance Method Details
#get(end_point, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/octocat_herder/connection.rb', line 46 def get(end_point, ={}) = .merge() if .has_key?(:headers) and .has_key(:headers) [:headers] = [:headers].merge([:headers]) end OctocatHerder::Connection.get(end_point, ) end |
#httparty_options ⇒ Object
11 12 13 |
# File 'lib/octocat_herder/connection.rb', line 11 def @httparty_options || {} end |