badgerkit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b3f0567b08710a9bc53f325d93b976b18176858
4
- data.tar.gz: 38fc7e67247b3e22b9aa3cafc7018120218a50ee
3
+ metadata.gz: 822e9d773d47df68eea29c955cd919744edc8bea
4
+ data.tar.gz: 1c4a16e972413f82d65cbde54a81cf6665e474ad
5
5
  SHA512:
6
- metadata.gz: 0c45b81716f4a64ae7a8e350de88e16175fa46a1d910649360f3b1eee7a8d4346062ae112f581be90bed3f6e1c70b5a91dd71abf7c827beeee94bb6964dfd6e3
7
- data.tar.gz: 31253c58700d88e9821b26c6bbfa705daca7bd4b16893ba80420b98554a0162033b6292d2e886671741b96e08ab7c4ff2df0d7c7dd681c8c916fff636e77be47
6
+ metadata.gz: 9abbdc52f23c645dbfe6d0b37f163e006d755aecef2fab2051908e762b3b61de8ae307cbfdf6215577378b1d18a3bb9763d459e27e439f089c7a2e1da8358dc9
7
+ data.tar.gz: 23fce28db088b59f033177b514a471b7e13168b331acc792edd0a733477e366aa1e364d4fb46af7df90728a7f31034cf090bf15ca29719fbb0aab63a14ec1541
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.1
6
+ - ruby-head
7
+
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: ruby-head
data/README.md CHANGED
@@ -1,6 +1,18 @@
1
1
  # Badgerkit
2
2
 
3
- TODO: Write a gem description
3
+ [![Gem Version](http://img.shields.io/gem/v/badgerkit.svg)][gem]
4
+ [![Build Status](http://img.shields.io/travis/saladdays-nl/badgerkit.rb.svg)][travis]
5
+ [![Coverage Status](http://img.shields.io/coveralls/saladdays-nl/badgerkit.rb.svg)][coveralls]
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/saladdays-nl/badgerkit.rb.svg)][codeclimate]
7
+ [![Dependency Status](http://img.shields.io/gemnasium/saladdays-nl/badgerkit.rb.svg)][gemnasium]
8
+
9
+ [gem]: https://rubygems.org/gems/badgerkit
10
+ [travis]: http://travis-ci.org/saladdays-nl/badgerkit.rb
11
+ [coveralls]: https://coveralls.io/r/saladdays-nl/badgerkit.rb
12
+ [codeclimate]: https://codeclimate.com/github/saladdays-nl/badgerkit.rb
13
+ [gemnasium]: https://gemnasium.com/saladdays-nl/badgerkit.rb
14
+
15
+ Simple api wrapper for submitting data to http://badgerhq.com
4
16
 
5
17
  ## Installation
6
18
 
@@ -16,18 +28,45 @@ $ bundle
16
28
 
17
29
  ## Usage
18
30
 
31
+ Without environment variables:
32
+
19
33
  ```ruby
20
- Badgerkit::Client.new(
21
- :source => 'github'
22
- :repo => 'saladdays-nl/badgerkit.rb'
23
- :name => 'Ruby documentation'
24
- ).post(
34
+ client = Badgerkit.new(
35
+ :access_token => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
36
+ :source => 'github',
37
+ :repo => 'saladdays-nl/badgerkit.rb'
38
+ )
39
+
40
+ client.post('Documentation',
25
41
  :value => 80,
26
42
  :commit_sha1 => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
27
43
  :branch => 'master'
28
44
  )
29
45
  ```
30
46
 
47
+ With the following environment variables:
48
+
49
+ ```ruby
50
+ ENV['BADGER_ACCESS_TOKEN'] = '0dbce1478e94053d4282ccd4ace154c82a3475d5'
51
+ ENV['BADGER_SOURCE'] = 'github'
52
+ ENV['BADGER_REPO'] = 'saladdays/badgerkit.rb'
53
+
54
+ Badgerkit.post('Documentation',
55
+ :value => 80,
56
+ :commit_sha1 => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
57
+ :branch => 'master'
58
+ )
59
+ ```
60
+
61
+ ## Supported Ruby Versions
62
+
63
+ This library is tested against Travis and aims to support the following Ruby
64
+ implementations:
65
+
66
+ * Ruby 1.9.3
67
+ * Ruby 2.0.0
68
+ * Ruby 2.1.1
69
+
31
70
  ## Contributing
32
71
 
33
72
  1. Fork it ( http://github.com/<my-github-username>/badgekit/fork )
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
data/badgerkit.gemspec CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'coveralls'
24
+ spec.add_development_dependency 'rspec', '>= 2.3'
23
25
 
24
26
  spec.add_dependency "httparty"
25
27
  spec.add_dependency "hashie"
data/lib/badgerkit.rb CHANGED
@@ -9,13 +9,20 @@ module Badgerkit
9
9
 
10
10
  # Alias for Badgerkit::Client.new
11
11
  #
12
- # @return [Badgerkit::Client.]
12
+ # @return [Badgerkit::Client]
13
13
  #
14
14
  def new(options={})
15
15
  @options = options
16
16
  Badgerkit::Client.new(options)
17
17
  end
18
18
 
19
+ ##
20
+ # Delegates to {Badgerkit::Client#post}
21
+ #
22
+ def post(*args)
23
+ new.post(*args)
24
+ end
25
+
19
26
  end # class << self
20
27
 
21
28
  end # Badgerkit
@@ -3,8 +3,10 @@ module Badgerkit
3
3
  # Responsible for constructing a client which is able to post values.
4
4
  #
5
5
  class Client
6
+ require 'httparty'
7
+ require 'hashie'
6
8
 
7
- attr_reader :path, :source, :repo, :name
9
+ attr_reader :path, :access_token, :source, :repo
8
10
 
9
11
  BASE_URI = 'http://badgerhq.com/'
10
12
 
@@ -12,24 +14,34 @@ module Badgerkit
12
14
  # Construct a new Badgekit::Client
13
15
  #
14
16
  # @param options [Hash]
17
+ # @option token [String] :token
15
18
  # @option options [String] :source
16
- # @option options [String] :repo
19
+ # @option options [String] :app
17
20
  # @option options [String] :name
21
+
18
22
  # @return [Badgerkit::Client]
19
23
  # @example
20
24
  # Badgerkit::Client.new(
21
- # :source => 'github'
22
- # :repo => 'saladdays-nl/badgekit'
23
- # :name => 'Ruby documentation'
25
+ # :access_token => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
26
+ # :source => 'github',
27
+ # :repo => 'saladdays-nl/badgerkit'
24
28
  # )
25
29
  #
26
30
  #
27
31
  def initialize(options={})
28
- @source = options[:source]
29
- @repo = options[:repo]
30
- @name = options[:name]
32
+ @access_token = ENV['BADGER_ACCESS_TOKEN'] || options[:access_token]
33
+ @source = ENV['BADGER_SOURCE'] || options[:source]
34
+ @repo = ENV['BADGER_REPO'] || options[:repo]
35
+ end
31
36
 
32
- @path = URI.escape("#{source}/#{repo}/#{name}")
37
+ ##
38
+ # Returns post path for badge.
39
+ #
40
+ # @param badge [String] the badge name
41
+ # @return [String] escaped path
42
+ #
43
+ def path_for(badge)
44
+ URI.escape("#{source}/#{repo}/#{badge}")
33
45
  end
34
46
 
35
47
  ##
@@ -41,15 +53,15 @@ module Badgerkit
41
53
  # @option attributes [String] :branch
42
54
  #
43
55
  # @example
44
- # client.post(
56
+ # client.post('Documentation',
45
57
  # :value => 80,
46
58
  # :commit_sha1 => '0dbce1478e94053d4282ccd4ace154c82a3475d5',
47
59
  # :branch => 'master'
48
60
  # )
49
61
  #
50
- def post(attributes={})
51
- attributes = { :value => attributes }
52
- response = HTTParty.post("#{BASE_URI}#{path}", :body => attributes).parsed_response
62
+ def post(badge, attributes={})
63
+ attributes = { :value => attributes, :access_token => access_token }
64
+ response = HTTParty.post("#{BASE_URI}#{path_for(badge)}", :body => attributes).parsed_response
53
65
  response = Hashie::Mash.new(response)
54
66
  end
55
67
 
@@ -1,4 +1,4 @@
1
1
  module Badgerkit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end # Badgerkit
4
4
 
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Badgerkit::Client do
4
+
5
+ describe '#initialize' do
6
+
7
+ it 'should be able to set options' do
8
+ client = Badgerkit::Client.new(
9
+ :access_token => 'some_token',
10
+ :source => 'github',
11
+ :repo => 'saladdays/badgerkit.rb',
12
+ )
13
+ client.access_token.should == 'some_token'
14
+ client.source.should == 'github'
15
+ client.repo.should == 'saladdays/badgerkit.rb'
16
+ end
17
+
18
+ end
19
+
20
+ describe '#path_for' do
21
+
22
+ it 'should return escaped path to submit to' do
23
+ client = Badgerkit::Client.new(
24
+ :access_token => 'some_token',
25
+ :source => 'github',
26
+ :repo => 'saladdays/badgerkit.rb',
27
+ )
28
+ client.path_for('(rb) roverage').should == "github/saladdays/badgerkit.rb/(rb)%20roverage"
29
+ end
30
+
31
+ end
32
+
33
+ describe '#post' do
34
+
35
+ it 'should post with correct params' do
36
+ client = Badgerkit::Client.new(
37
+ :access_token => 'some_token',
38
+ :source => 'github',
39
+ :repo => 'saladdays/badgerkit.rb',
40
+ )
41
+
42
+ HTTParty.stub(:post).and_return(HTTPartyProxy.new)
43
+ HTTParty.should_receive(:post).with("http://badgerhq.com/github/saladdays/badgerkit.rb/Documentation",
44
+ :body => {
45
+ :value => {
46
+ :value => 90,
47
+ :branch => "master",
48
+ :commit_sha1 => "0dbce1478e94053d4282ccd4ace154c82a3475d5"
49
+ },
50
+ :access_token => 'some_token'
51
+ }
52
+ )
53
+
54
+ client.post('Documentation',
55
+ :value => 90,
56
+ :branch => 'master',
57
+ :commit_sha1 => '0dbce1478e94053d4282ccd4ace154c82a3475d5'
58
+ )
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Badgerkit do
4
+
5
+ subject { Badgerkit.new }
6
+
7
+ describe '.new' do
8
+
9
+ it 'is a Badgerkit::Client' do
10
+ expect(subject).to be_a Badgerkit::Client
11
+ end
12
+
13
+ end
14
+
15
+ describe '.post' do
16
+
17
+ it 'should delegate to Badgerkit::Client#post' do
18
+ HTTParty.stub(:post).and_return({})
19
+
20
+ Badgerkit::Client.any_instance.should_receive(:post).with('Documenation', :value => 9)
21
+
22
+ Badgerkit.post('Documenation', :value => 9)
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,15 @@
1
+ ## Test coverage
2
+
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+
6
+ require 'support/httparty_proxy'
7
+
8
+ ## Rspec
9
+
10
+ require 'rspec'
11
+ require 'rspec/autorun'
12
+
13
+ ## Load alfred
14
+
15
+ require 'badgerkit'
@@ -0,0 +1,10 @@
1
+ # @private
2
+ class HTTPartyProxy
3
+
4
+ attr_reader :parsed_response
5
+
6
+ def initialize(attributes={})
7
+ @parsed_response = attributes
8
+ end
9
+
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: badgerkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan van Zonneveld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-23 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: httparty
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +102,7 @@ extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
76
104
  - ".gitignore"
105
+ - ".travis.yml"
77
106
  - Gemfile
78
107
  - LICENSE.txt
79
108
  - README.md
@@ -82,6 +111,10 @@ files:
82
111
  - lib/badgerkit.rb
83
112
  - lib/badgerkit/client.rb
84
113
  - lib/badgerkit/version.rb
114
+ - spec/badgerkit/client_spec.rb
115
+ - spec/badgerkit_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/httparty_proxy.rb
85
118
  homepage: https://github.com/saladdays-nl/badgerkit.rb
86
119
  licenses:
87
120
  - MIT
@@ -106,4 +139,8 @@ rubygems_version: 2.2.2
106
139
  signing_key:
107
140
  specification_version: 4
108
141
  summary: Toolkit for badgerhq.com
109
- test_files: []
142
+ test_files:
143
+ - spec/badgerkit/client_spec.rb
144
+ - spec/badgerkit_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/support/httparty_proxy.rb