class Badgerkit::Client

Responsible for constructing a client which is able to post values to badgherhq.com

Constants

BASE_URI

The base uri the perform requests to.

Attributes

access_token[R]
path[R]
repo[R]
source[R]

Public Class Methods

new(options={}) click to toggle source

Construct a new Badgerkit::Client

@param options [Hash] @option token [String] :token @option options [String] :source @option options [String] :app @option options [String] :name @return [Badgerkit::Client] @example

client = Badgerkit::Client.new(
  :access_token => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
  :source       => 'github',
  :repo         => 'saladdays-nl/badgerkit'
)
# File lib/badgerkit/client.rb, line 34
def initialize(options={})
  @access_token = ENV['BADGER_ACCESS_TOKEN'] || options[:access_token]
  @source       = ENV['BADGER_SOURCE']       || options[:source]
  @repo         = ENV['BADGER_REPO']         || options[:repo]
end

Public Instance Methods

path_for(badge) click to toggle source

Returns post path for badge.

@param badge [String] the badge name @return [String] escaped path

# File lib/badgerkit/client.rb, line 46
def path_for(badge)
  URI.escape("#{source}/#{repo}/#{badge}")
end
post(badge, attributes={}) click to toggle source

Post a value.

@param attributes [Hash] @option attributes [String, Integer, Float] :value @option attributes [String] :commit_sha1 @option attributes [String] :branch @option attributes [File] :archive @return [Hashie::Mash] @example

client.post('Documentation',
  :value       => 80,
  :commit_sha1 => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
  :branch      => 'master'
)
# 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