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 to badgherhq.com
Constant Summary collapse
- BASE_URI =
The base uri the perform requests to.
'https://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
Construct a new Badgerkit::Client.
-
#path_for(badge) ⇒ String
Returns post path for badge.
-
#post(badge, attributes = {}) ⇒ Hashie::Mash
Post a value.
Constructor Details
#initialize(options = {}) ⇒ Badgerkit::Client
Construct a new Badgerkit::Client
34 35 36 37 38 |
# File 'lib/badgerkit/client.rb', line 34 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.
10 11 12 |
# File 'lib/badgerkit/client.rb', line 10 def access_token @access_token end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/badgerkit/client.rb', line 10 def path @path end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
10 11 12 |
# File 'lib/badgerkit/client.rb', line 10 def repo @repo end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/badgerkit/client.rb', line 10 def source @source end |
Instance Method Details
#path_for(badge) ⇒ String
Returns post path for badge.
46 47 48 |
# File 'lib/badgerkit/client.rb', line 46 def path_for(badge) URI.escape("#{source}/#{repo}/#{badge}") end |
#post(badge, attributes = {}) ⇒ Hashie::Mash
Post a value.
66 67 68 69 70 |
# File 'lib/badgerkit/client.rb', line 66 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 |