Class: Badgerkit::Client
- Inherits:
-
Object
- Object
- Badgerkit::Client
- Defined in:
- lib/badgerkit/client.rb
Overview
Responsible for constructing a client which is able to post values.
Constant Summary collapse
- BASE_URI =
'http://badgerhq.com/'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #initialize(options = {}) ⇒ Badgerkit::Client constructor
-
#path_for(badge) ⇒ String
Returns post path for badge.
-
#post(badge, attributes = {}) ⇒ Object
Post a value.
Constructor Details
#initialize(options = {}) ⇒ Badgerkit::Client
31 32 33 34 35 |
# File 'lib/badgerkit/client.rb', line 31 def initialize(={}) @access_token = ENV['BADGER_ACCESS_TOKEN'] || [:access_token] @source = ENV['BADGER_SOURCE'] || [:source] @repo = ENV['BADGER_REPO'] || [:repo] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/badgerkit/client.rb', line 9 def access_token @access_token end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/badgerkit/client.rb', line 9 def path @path end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
9 10 11 |
# File 'lib/badgerkit/client.rb', line 9 def repo @repo end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/badgerkit/client.rb', line 9 def source @source end |
Instance Method Details
#path_for(badge) ⇒ String
Returns post path for badge.
43 44 45 |
# File 'lib/badgerkit/client.rb', line 43 def path_for(badge) URI.escape("#{source}/#{repo}/#{badge}") end |
#post(badge, attributes = {}) ⇒ Object
Post a value.
62 63 64 65 66 |
# File 'lib/badgerkit/client.rb', line 62 def post(badge, attributes={}) attributes = { :value => attributes, :access_token => access_token } response = HTTMultiParty.post("#{BASE_URI}#{path_for(badge)}", :body => attributes).parsed_response response = Hashie::Mash.new(response) end |