Class: Badgerkit::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Badgerkit::Client

Examples:

Badgerkit::Client.new(
  :access_token => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
  :source       => 'github',
  :repo         => 'saladdays-nl/badgerkit'
)


31
32
33
34
35
# File 'lib/badgerkit/client.rb', line 31

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

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.

Parameters:

  • badge (String) —

    the badge name

Returns:

  • (String) —

    escaped path



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.

Examples:

client.post('Documentation',
  :value       => 80,
  :commit_sha1 => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
  :branch      => 'master'
)

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):

  • :value (String, Integer, Float)
  • :commit_sha1 (String)
  • :branch (String)


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