coderbits 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37c520a44bcd474cb90e596f57d2b01f1bc85c50
4
- data.tar.gz: fd5aacad09bb37015e0415525e76ca362d495f44
3
+ metadata.gz: c7a25f426cf29818d22d8116704b55ed76cc6bbe
4
+ data.tar.gz: f342a83bb9ff776a1d4d75fcdaa94c56e4366b5f
5
5
  SHA512:
6
- metadata.gz: 9e49f64390054b1c8bdbdcb909e2ca468b830e3592157da613a690abb9f020f9c4682f4128bbd3b553bd1297b82f9a6839672f4b92965e43a6ff3455fc4c94af
7
- data.tar.gz: 5d53b23a39b2a5426a9e7528ea0bcceaf4471cee7a35e3065532e862cb5dd2852db9471773392580f36c3a39a53b858cce29009e9c906d30481c9dcdad435b8a
6
+ metadata.gz: 3a250d1acc51aa355da3e3c9f39095815e9a0518648d37ed608c48d5a72ad523835a45898f4374322363a7950593d02cd3b7dde02a9a034504cab73f47fa226a
7
+ data.tar.gz: 9e9317aec34d3e9397176d58f4474f145d93f940abb338d804603e0117bbdaa3a25d26f9ce19438bb3f4e14f5c622a5b760e0a0b6be55e7d908064830d73288d
@@ -1,3 +1,8 @@
1
+ ### 0.0.2
2
+
3
+ * Refactor
4
+ * Add specs
5
+
1
6
  ### 0.0.1
2
7
 
3
8
  * Initial
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # coderbits
2
2
 
3
+ [![Gem version](https://badge.fury.io/rb/coderbits.png)](https://rubygems.org/gems/coderbits)
4
+ [![Build Status](https://secure.travis-ci.org/artemeff/coderbits.png)][travis]
5
+ [![Code Climate](https://codeclimate.com/github/artemeff/coderbits.png)](https://codeclimate.com/github/artemeff/coderbits)
3
6
  [![Dependency Status](https://gemnasium.com/artemeff/coderbits.png)](https://gemnasium.com/artemeff/coderbits)
4
7
 
5
8
  Simple wrapper for the Coderbits API
@@ -12,12 +15,35 @@ Simple wrapper for the Coderbits API
12
15
 
13
16
  ```ruby
14
17
  require 'coderbits'
18
+
19
+ # Create sprite image with css code for earned badges
20
+ Coderbits.glue('artemeff').run!
21
+
22
+ # With options
23
+ Coderbits.glue('artemeff', glue_options).run!
24
+
25
+ # Get user info
26
+ Codebits.get 'artemeff'
15
27
  ```
16
28
 
17
29
  ### Options
18
30
 
19
- ```ruby
31
+ __Glue options__:
20
32
 
33
+ ```ruby
34
+ :badge_size # badges size for download
35
+ :save_to # path for files
36
+ :layout # horizontal, vertical or packed
37
+ :style # css, scss or sass
38
+ :library # rmagick or chunkypng
39
+ :selector # selector
40
+ :padding # add padding to each sprite
41
+ :margin # add margin to each sprite
42
+ :nocomments # suppress generation of comments in output stylesheet
43
+ :output_image # output location for generated image
44
+ :output_style # output location for generated stylesheet
45
+ :width # fix width of each sprite to a specific size
46
+ :height # fix height of each sprite to a specific size
21
47
  ```
22
48
 
23
49
  ### Copyright
@@ -43,31 +43,21 @@ module Coderbits
43
43
 
44
44
  # download images
45
45
  images.each do |img|
46
- unless @options[:badge_size] == 64
47
- # parse image name
48
- eimg = img.match /(.+)-(\d+).png/
49
-
50
- # build with :badge_size
51
- img = "#{eimg[1]}-#{@options[:badge_size]}.png"
52
- end
53
-
46
+ # specify badge size
47
+ img = change_size img unless @options[:badge_size] == 64
48
+
54
49
  # download image
55
- response = connection.get("https://coderbits.com/images/badges/#{img}")
50
+ response = connection.get "https://coderbits.com/images/badges/#{img}"
56
51
 
57
52
  # save to disk
58
53
  if response.headers["content-type"] == "image/png"
59
- File.open("#{@options[:save_to]}/badges/#{img}", 'wb') { |f| f.write response.body }
54
+ File.open("#{@options[:save_to]}/badges/#{img.downcase}", 'wb') { |f| f.write response.body }
60
55
  end
61
56
  end
62
57
  end
63
58
 
64
59
  def merge_images
65
- SpriteFactory.run! "#{@options[:save_to]}/badges",
66
- css_engine: @options[:css_engine],
67
- selector: 'span.icon_',
68
- output_image: "#{@options[:save_to]}/out.png",
69
- output_style: "#{@options[:save_to]}/out.css",
70
- nocomments: true
60
+ SpriteFactory.run! "#{@options[:save_to]}/badges", @options
71
61
  end
72
62
 
73
63
  def generate_html
@@ -75,28 +65,40 @@ module Coderbits
75
65
  end
76
66
 
77
67
  def safe options
78
- #
68
+ # select only allowed options
79
69
  options = options.select { |k, v| OPTIONS.include? k }
80
70
 
81
71
  dflt = {
82
- badge_size: 64, # badges size for download
83
- save_to: './', # path for files
84
-
85
- layout: 'packed', # horizontal, vertical or packed
86
- style: 'css', # css, scss or sass
87
- library: 'chunkypng', # rmagick or chunkypng
88
- selector: 'span.badge_', # selector
89
- padding: 0, # add padding to each sprite
90
- margin: 0, # add margin to each sprite
91
- nocomments: true # suppress generation of comments in output stylesheet
72
+ badge_size: 64, # badges size for download
73
+ save_to: './', # path for files
74
+
75
+ layout: 'packed', # horizontal, vertical or packed
76
+ style: 'css', # css, scss or sass
77
+ library: 'chunkypng', # rmagick or chunkypng
78
+ selector: '.badge-', # selector
79
+ padding: 0, # add padding to each sprite
80
+ margin: 0, # add margin to each sprite
81
+ nocomments: true # suppress generation of comments in output stylesheet
92
82
  }
93
83
 
94
84
  dflt[:output_image] = "#{dflt[:save_to]}/badges.png" # output location for generated image
95
85
  dflt[:output_style] = "#{dflt[:save_to]}/badges.css" # output location for generated stylesheet
86
+
96
87
  dflt[:width] = dflt[:badge_size] # fix width of each sprite to a specific size
97
88
  dflt[:height] = dflt[:badge_size] # fix height of each sprite to a specific size
98
89
 
99
90
  @options = dflt.merge options
100
91
  end
92
+
93
+ private
94
+
95
+ def change_size filename
96
+ # parse image name
97
+ params = filename.match /([A-z\-_]+)(\d+).png/
98
+
99
+ # custom badge size
100
+ "#{params[1]}#{@options[:badge_size]}.png"
101
+ end
102
+
101
103
  end
102
- end
104
+ end
@@ -1,3 +1,3 @@
1
1
  class Colos
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coderbits::Client do
4
+
5
+ describe ".new" do
6
+ it "should have connection" do
7
+ expect(Coderbits::Client.new.connection).to be_a Faraday::Connection
8
+ end
9
+ end
10
+
11
+ describe ".get" do
12
+
13
+ describe "without options" do
14
+ before do
15
+ @data = Coderbits::Client.new.get 'artemeff'
16
+ end
17
+
18
+ it "should have user data" do
19
+ expect(@data).to be_a Hash
20
+ end
21
+
22
+ it "should have username" do
23
+ @data.should include :username
24
+ end
25
+ end
26
+
27
+ describe "with options" do
28
+ it "should be a String with callback option" do
29
+ data = Coderbits::Client.new.get 'artemeff', callback: 'testFunc'
30
+
31
+ data.should be_an_instance_of String
32
+ end
33
+
34
+ it "should be a Hash with account option" do
35
+ data = Coderbits::Client.new.get 'artemeff', account: 'github'
36
+
37
+ data.should be_an_instance_of Hash
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#safe" do
43
+ before do
44
+ @client = Coderbits::Client.new
45
+
46
+ @options = {
47
+ bad_option: false,
48
+ account: 'github',
49
+ callback: 'testFunc'
50
+ }
51
+ end
52
+
53
+ it "should have bad option" do
54
+ @options.should include :bad_option
55
+ end
56
+
57
+ it "should delete bad options" do
58
+ safe = @client.send :safe, @options
59
+
60
+ safe.should_not include :bad_option
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coderbits::Glue do
4
+
5
+ describe ".new" do
6
+ before do
7
+ @glue = Coderbits::Glue.new 'artemeff'
8
+ end
9
+
10
+ it "should have username" do
11
+ @glue.instance_variable_get(:@username).should have(8).characters
12
+ end
13
+ end
14
+
15
+ describe ".run!" do
16
+ it "..." do
17
+ pending "Write tests"
18
+ end
19
+ end
20
+
21
+ describe ".download_images" do
22
+ it "..." do
23
+ pending "Write tests"
24
+ end
25
+ end
26
+
27
+ describe ".merge_images" do
28
+ it "..." do
29
+ pending "Write tests"
30
+ end
31
+ end
32
+
33
+ describe ".generate_html" do
34
+ it "..." do
35
+ pending "Write tests"
36
+ end
37
+ end
38
+
39
+ describe "#safe" do
40
+ before do
41
+ @glue = Coderbits::Glue.new 'artemeff'
42
+
43
+ @options = {
44
+ bad_option: false,
45
+ save_to: './'
46
+ }
47
+ end
48
+
49
+ it "should have bad option" do
50
+ @options.should include :bad_option
51
+ end
52
+
53
+ it "should delete bad options" do
54
+ safe = @glue.send :safe, @options
55
+
56
+ safe.should_not include :bad_option
57
+ end
58
+ end
59
+
60
+ end
@@ -2,71 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe Coderbits do
4
4
 
5
- describe "#new" do
6
- it "should have correct frequency" do
7
- colos = Colos.new frequency: 1.4
8
- colos.options[:frequency].should == 1.4
9
- end
10
-
11
- it "should have correct randomizr" do
12
- colos = Colos.new randomizr: 20
13
- colos.options[:randomizr].should == 20
14
- end
15
- end
16
-
17
- describe "#color" do
18
- it "'test' should be '3a1be1'" do
19
- @colos.color("test").should == "3a1be1"
20
- end
21
-
22
- it "'word' should be '395e9a" do
23
- @colos.color("word").should == "395e9a"
5
+ describe ".new" do
6
+ it "is a Coderbits::Client" do
7
+ expect(Coderbits.new('artemeff')).to be_a Coderbits::Client
24
8
  end
25
9
  end
26
10
 
27
- describe "#colors" do
28
- it "'test' should be ['ba6714', '3a1be1', '15291c']" do
29
- @colos.colors("test").should == ["ba6714", "3a1be1", "15291c"]
30
- end
31
-
32
- it "'word' should be '['b7d989', '395e9a', '14e8c0']'" do
33
- @colos.colors("word").should == ["b7d989", "395e9a", "14e8c0"]
11
+ describe ".get" do
12
+ it "is a Coderbits::Client" do
13
+ expect(Coderbits.get('artemeff')).to be_a Hash
34
14
  end
35
15
  end
36
16
 
37
- describe "#ip" do
38
- it "'173.194.32.14' should be 'adc220'" do
39
- @colos.ip("173.194.32.14").should == "adc220"
40
- end
41
-
42
- it "'176.15.222.136' should be 'b00fde'" do
43
- @colos.ip("176.15.222.136").should == "b00fde"
17
+ describe ".glue" do
18
+ it "is a Coderbits::Glue" do
19
+ expect(Coderbits.glue('artemeff')).to be_a Coderbits::Glue
44
20
  end
45
21
  end
46
22
 
47
- describe "#ips" do
48
- it "first of '173.194.32.14' should be 'adc220'" do
49
- @colos.ips("173.194.32.14").first.should == "adc220"
50
- end
51
-
52
- it "first of '176.15.222.136' should be 'b00fde'" do
53
- @colos.ips("176.15.222.136").first.should == "b00fde"
54
- end
55
-
56
- it "last of '173.194.32.14' should be '0e20c2'" do
57
- @colos.ips("173.194.32.14").last.should == "0e20c2"
58
- end
59
-
60
- it "last of '176.15.222.136' should be '88de0f'" do
61
- @colos.ips("176.15.222.136").last.should == "88de0f"
62
- end
63
-
64
- it "size of '173.194.32.14' should be 24" do
65
- @colos.ips("173.194.32.14").size.should == 24
66
- end
67
- end
68
-
69
- describe "#options" do
70
- # write tests
71
- end
72
23
  end
@@ -1,4 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
3
4
  require 'rspec'
4
5
  require 'coderbits'
6
+ require 'coveralls'
7
+
8
+ Coveralls.wear!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderbits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Artemev
@@ -96,6 +96,8 @@ files:
96
96
  - lib/coderbits/glue.rb
97
97
  - lib/coderbits/version.rb
98
98
  - lib/coderbits.rb
99
+ - spec/coderbits/client_spec.rb
100
+ - spec/coderbits/glue_spec.rb
99
101
  - spec/coderbits_spec.rb
100
102
  - spec/spec_helper.rb
101
103
  homepage: http://github.com/artemeff/coderbits
@@ -123,6 +125,8 @@ signing_key:
123
125
  specification_version: 4
124
126
  summary: Coderbits API wrapper
125
127
  test_files:
128
+ - spec/coderbits/client_spec.rb
129
+ - spec/coderbits/glue_spec.rb
126
130
  - spec/coderbits_spec.rb
127
131
  - spec/spec_helper.rb
128
132
  has_rdoc: