Class: Octoplex::Connection
- Inherits:
-
Object
- Object
- Octoplex::Connection
- Defined in:
- lib/octoplex/connection.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#conn_options ⇒ Object
readonly
Returns the value of attribute conn_options.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rate_limit ⇒ Object
readonly
Returns the value of attribute rate_limit.
-
#rate_limit_remaining ⇒ Object
readonly
Returns the value of attribute rate_limit_remaining.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #authentication_param ⇒ Object
- #cache(path, response) ⇒ Object
- #cache_size ⇒ Object
- #cached(path) ⇒ Object
- #clear_cache ⇒ Object
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #is_cached?(path) ⇒ Boolean
- #post(path, body) ⇒ Object
- #put(path, body) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/octoplex/connection.rb', line 11 def initialize( = {}) ||= {} @options = { :per_page => 100, :enable_caching => true, :logging => false, :token => nil }.update() @conn_options = { :logging => @options.delete(:logging), :access_token => @options.delete(:token), :enable_caching => @options.delete(:enable_caching) } @token = @conn_options[:access_token] @rate_limit = @rate_limit_remaining = 0 setup end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
9 10 11 |
# File 'lib/octoplex/connection.rb', line 9 def conn @conn end |
#conn_options ⇒ Object (readonly)
Returns the value of attribute conn_options.
9 10 11 |
# File 'lib/octoplex/connection.rb', line 9 def @conn_options end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/octoplex/connection.rb', line 9 def @options end |
#rate_limit ⇒ Object (readonly)
Returns the value of attribute rate_limit.
9 10 11 |
# File 'lib/octoplex/connection.rb', line 9 def rate_limit @rate_limit end |
#rate_limit_remaining ⇒ Object (readonly)
Returns the value of attribute rate_limit_remaining.
9 10 11 |
# File 'lib/octoplex/connection.rb', line 9 def rate_limit_remaining @rate_limit_remaining end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/octoplex/connection.rb', line 9 def token @token end |
Instance Method Details
#authentication_param ⇒ Object
43 44 45 |
# File 'lib/octoplex/connection.rb', line 43 def authentication_param {:access_token => token} end |
#cache(path, response) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/octoplex/connection.rb', line 63 def cache(path, response) if [:enable_caching] == true (@cache ||= {})[path.to_s] = response end response end |
#cache_size ⇒ Object
82 83 84 |
# File 'lib/octoplex/connection.rb', line 82 def cache_size (@cache ||= {}).keys.size end |
#cached(path) ⇒ Object
70 71 72 |
# File 'lib/octoplex/connection.rb', line 70 def cached(path) (@cache ||= {})[path.to_s] end |
#clear_cache ⇒ Object
78 79 80 |
# File 'lib/octoplex/connection.rb', line 78 def clear_cache @cache = {} end |
#delete(path) ⇒ Object
59 60 61 |
# File 'lib/octoplex/connection.rb', line 59 def delete(path) request(path, :delete) end |
#get(path) ⇒ Object
47 48 49 |
# File 'lib/octoplex/connection.rb', line 47 def get(path) request(path, :get) end |
#is_cached?(path) ⇒ Boolean
74 75 76 |
# File 'lib/octoplex/connection.rb', line 74 def is_cached?(path) (@cache ||= {}).has_key?(path) end |
#post(path, body) ⇒ Object
51 52 53 |
# File 'lib/octoplex/connection.rb', line 51 def post(path, body) request(path, :post, body) end |
#put(path, body) ⇒ Object
55 56 57 |
# File 'lib/octoplex/connection.rb', line 55 def put(path, body) request(path, :put, body) end |
#setup ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/octoplex/connection.rb', line 32 def setup @conn = Faraday.new(:url => 'https://api.github.com') do |builder| builder.use Faraday::Request::JSON builder.use Faraday::Response::Logger if [:logging].eql?(true) builder.use Faraday::Adapter::NetHttp builder.use Faraday::Response::Hashr builder.use Faraday::Response::RaiseOctoplexError builder.use Faraday::Response::MultiJson end end |