coderbits 0.1.0 → 1.0.0

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: 0f3f89f4d80c71f4f30ccec6aeb3e3e4537d99b7
4
- data.tar.gz: 4f4ec14200e32a65f7a2006c49771fa0a9df8183
3
+ metadata.gz: c31dfc8d60d7f5ad255e2f6826b0d50c202b09ac
4
+ data.tar.gz: c8b8b1a85c77bb29b57d1de768616edc724ade41
5
5
  SHA512:
6
- metadata.gz: d14bfbc1f15991c35d29f491e3ca034c491d001f0aab185a4734c5173869b5b3428d32a199364612236b112bc397cfd695719c0b69f64767988a2c1f485b1ca7
7
- data.tar.gz: 494a6e187229d9de9f030c540a4b4157abf6a495b1a00e39550553711c115a31fc5b7bd36ab875e3cf729f6a422013e4bf613a061b73475153df0debb2c8a96f
6
+ metadata.gz: d957113f9ee4d8d9f6ffddfff4aafe0d77ba55ce05b6f739327b9f3d9ca3c1ae3cb2cf324a89f8f4697127e0d6eae116ddcf5ac6472220f47134623d8daa849e
7
+ data.tar.gz: eac8e94bbf1632fb8a7657ab9c0feb69562c2918e3dfa6ccaef69b5aa4a5d71c85570240f67b118b1875a353b2c3368a2f968628da5b6d943de045b907edfdac
@@ -1,3 +1,14 @@
1
+ ### [1.0.0]
2
+
3
+ * Remove .glue method
4
+ * Remove unused dependencies
5
+ * Enhance specs
6
+
7
+ ### [0.1.0](https://github.com/artemeff/coderbits/commit/3dd43979b91e1d91aa1400a50b25acccdcfdf054)
8
+
9
+ * Add html code generator
10
+ * Refactoring
11
+
1
12
  ### 0.0.3
2
13
 
3
14
  * :save_to fix
data/README.md CHANGED
@@ -16,34 +16,16 @@ Simple wrapper for the Coderbits API
16
16
  ```ruby
17
17
  require 'coderbits'
18
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
19
  # Get user info
26
20
  Codebits.get 'artemeff'
27
- ```
28
21
 
29
- ### Options
22
+ # Or you may initialize connection
23
+ client = Coderbits.new
30
24
 
31
- __Glue options__:
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
25
+ # And get data by this way
26
+ client.get 'artemeff'
45
27
  ```
46
28
 
47
29
  ### Copyright
48
30
 
49
- Copyright (c) 2012 Yuri Artemev. See LICENSE.txt for further details.
31
+ Copyright (c) 2012 Yuri Artemev. See [LICENSE](https://github.com/artemeff/coderbits/blob/master/LICENSE) for further details.
@@ -1,13 +1,14 @@
1
1
  # coding: utf-8
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require "coderbits/version"
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = "coderbits"
7
- s.version = Colos::VERSION
8
+ s.version = Coderbits::VERSION
8
9
  s.authors = ["Yuri Artemev"]
9
10
  s.email = ["i@artemeff.com"]
10
- s.homepage = "http://github.com/artemeff/coderbits"
11
+ s.homepage = "https://github.com/artemeff/coderbits"
11
12
  s.description = %q{Simple wrapper for the Coderbits API}
12
13
  s.summary = %q{Coderbits API wrapper}
13
14
  s.files = %w(CHANGELOG.md README.md LICENSE Rakefile coderbits.gemspec)
@@ -17,11 +18,7 @@ Gem::Specification.new do |s|
17
18
  s.require_paths = ['lib']
18
19
  s.test_files = Dir.glob("spec/**/*")
19
20
 
20
- s.add_development_dependency 'bundler', '~> 1.0'
21
21
  s.add_dependency 'faraday', '~> 0.8'
22
- s.add_dependency 'faraday_middleware', '~> 0.8'
23
- s.add_dependency 'multi_json', '~> 1.7'
24
- s.add_dependency 'sprite-factory', '~> 1.5'
25
- s.add_dependency 'chunky_png', '~> 1.2'
22
+ s.add_dependency 'multi_json', '~> 1.3'
26
23
  s.add_dependency 'hashie', '~> 2.0'
27
24
  end
@@ -1,26 +1,23 @@
1
- require 'sprite_factory'
2
1
  require 'multi_json'
3
2
  require 'hashie'
4
3
  require 'faraday'
5
- require 'faraday_middleware'
6
4
 
7
- require 'coderbits/defaults'
8
5
  require 'coderbits/client'
9
- require 'coderbits/object'
10
- require 'coderbits/glue'
6
+ require 'coderbits/version'
11
7
 
12
8
  module Coderbits
13
9
  class << self
14
- # Alias for Coderbits::Client.new.get
15
- def new username, options = {}
16
- Coderbits::Client.new.get username, options
10
+ # alias for Coderbits::Client.new
11
+ def new options = {}
12
+ Coderbits::Client.new options
17
13
  end
18
-
19
- alias_method :get, :new
20
14
 
21
- # Alias for Coderbits::Glue.new(...)
22
- def glue username, options = {}
23
- Coderbits::Glue.new username, options
15
+ # alias for Coderbits::Client.new.get
16
+ def get username, options = {}
17
+ Coderbits::Client.new.get username, options
24
18
  end
25
19
  end
20
+
21
+ # attach Hashie to data
22
+ class Object < Hashie::Mash; end
26
23
  end
@@ -1,26 +1,30 @@
1
1
  module Coderbits
2
2
  class Client
3
- # valid options
4
- OPTIONS = [:account, :callback]
3
+ # default faraday options
4
+ BASE_URL = "https://coderbits.com/"
5
+ HEADERS = { accept: 'application/json' }
6
+ SSL = { verify: false }
5
7
 
6
- # connection
8
+ # faraday instance only for reading
7
9
  attr_reader :connection
8
10
 
9
- # Coderbits::Client.new
10
- # establish faraday connection
11
+ # create instance of faraday
11
12
  def initialize options = {}
12
- options[:url] ||= Coderbits::Defaults::BASE_URL
13
- options[:headers] ||= Coderbits::Defaults::HEADERS
14
- options[:ssl] ||= Coderbits::Defaults::SSL
13
+ options = safe(options, [:headers, :ssl])
15
14
 
16
- @connection = Faraday.new(options)
15
+ params = {
16
+ url: BASE_URL,
17
+ headers: options[:headers] || HEADERS.merge({'User-Agent' => "Ruby Coderbits #{Coderbits::VERSION}"}),
18
+ ssl: options[:ssl] || SSL
19
+ }
20
+
21
+ @connection = Faraday.new params
17
22
  end
18
23
 
19
- # Coderbits::Client.new.get username: 'artemeff'
20
24
  # gets user data
21
25
  def get username, options = {}
22
26
  begin
23
- response = @connection.get "/#{username}.json", safe(options)
27
+ response = @connection.get "/#{username}.json", safe(options, [:account, :callback])
24
28
 
25
29
  status = response.status
26
30
  error = false
@@ -48,10 +52,9 @@ module Coderbits
48
52
 
49
53
  private
50
54
 
51
- # safety option
52
- def safe options
53
- options.select { |k, v| OPTIONS.include? k }
55
+ def safe options, allowed
56
+ options.select { |k, v| allowed.include? k }
54
57
  end
55
58
 
56
59
  end
57
- end
60
+ end
@@ -1,3 +1,3 @@
1
- class Colos
2
- VERSION = "0.1.0"
3
- end
1
+ module Coderbits
2
+ VERSION = "1.0.0"
3
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Coderbits::Client do
4
4
 
5
5
  describe ".new" do
6
- it "should have connection" do
6
+ it "setup faraday instance" do
7
7
  expect(Coderbits::Client.new.connection).to be_a Faraday::Connection
8
8
  end
9
9
  end
@@ -11,75 +11,84 @@ describe Coderbits::Client do
11
11
  describe ".get" do
12
12
 
13
13
  describe "without options" do
14
- before do
15
- @data = Coderbits::Client.new.get 'artemeff'
16
- end
14
+ let(:data) { Coderbits::Client.new.get 'artemeff' }
17
15
 
18
- it "should be a Coderbits::Object instance" do
19
- expect(@data).to be_a Coderbits::Object
16
+ it "is a Coderbits::Object instance" do
17
+ expect(data).to be_a Coderbits::Object
20
18
  end
21
19
 
22
- it "should return status eq 200" do
23
- @data.status.should be 200
20
+ it "return status 200" do
21
+ data.status.should be 200
24
22
  end
25
23
 
26
- it "shouldn't have error" do
27
- @data.error.should be false
24
+ it "runs without errors" do
25
+ data.error.should be false
28
26
  end
29
27
 
30
- it "should have username" do
31
- @data.should include :username
28
+ it "have username" do
29
+ data.should include :username
32
30
  end
33
31
  end
34
32
 
35
33
  describe "with options" do
36
- it "should be a String with callback option" do
37
- data = Coderbits::Client.new.get 'artemeff', callback: 'testFunc'
38
-
39
- data.should be_an_instance_of String
40
- end
34
+ describe "callback" do
35
+ let(:data) { Coderbits::Client.new.get 'artemeff', callback: 'callbackFunction' }
41
36
 
42
- it "should be a Coderbits::Object with account option" do
43
- data = Coderbits::Client.new.get 'artemeff', account: 'github'
37
+ it "return string" do
38
+ expect(data).to be_a String
39
+ end
44
40
 
45
- data.should be_an_instance_of Coderbits::Object
41
+ it "have callback function" do
42
+ data.should include("callbackFunction")
43
+ end
46
44
  end
45
+
46
+ #describe "account" do
47
+ # let(:data) { Coderbits::Client.new.get 'artemeff', account: 'github' }
48
+ #
49
+ # it do
50
+ # pending "i don't know what is that, but i should wrote this"
51
+ # end
52
+ #end
47
53
  end
48
54
 
49
- describe "with nonexistent user" do
50
- before do
51
- @data = Coderbits::Client.new.get "prettyuserthatdoesntexist#{rand(10)}"
52
- end
55
+ describe "with user that does not exist" do
56
+ let(:data) { Coderbits::Client.new.get "i_am_not_in_danger_skyler_i_am_the_danger" }
53
57
 
54
- it "should have 200 status" do
55
- @data.status.should be 200
58
+ it "return status 200" do
59
+ data.status.should be 200
56
60
  end
57
61
 
58
- it "should have error" do
59
- @data.error.should match "User not found"
62
+ it "have errors" do
63
+ data.error.should match "User not found"
60
64
  end
61
65
  end
62
66
  end
63
67
 
64
68
  describe "#safe" do
65
- before do
66
- @client = Coderbits::Client.new
67
-
68
- @options = {
69
- bad_option: false,
70
- account: 'github',
71
- callback: 'testFunc'
69
+ let(:client) { Coderbits::Client.new }
70
+ let(:allowed) { [:foo, :bar] }
71
+ let(:options) do
72
+ {
73
+ foo: 1,
74
+ bar: 2,
75
+ baz: 3
72
76
  }
73
77
  end
74
78
 
75
- it "should have bad option" do
76
- @options.should include :bad_option
79
+ it "have bad option" do
80
+ options.should include :baz
81
+ end
82
+
83
+ it "delete bad option" do
84
+ client.send(:safe, options, allowed).should_not include :baz
77
85
  end
78
86
 
79
- it "should delete bad options" do
80
- safe = @client.send :safe, @options
87
+ it "have allowed options after safing" do
88
+ params = client.send(:safe, options, allowed)
81
89
 
82
- safe.should_not include :bad_option
90
+ params.should include :foo
91
+ params.should include :bar
83
92
  end
84
93
  end
85
94
 
@@ -1,17 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Coderbits do
4
-
5
- describe ".new and .get" do
6
- it "is a Coderbits::Client" do
7
- expect(Coderbits.new('artemeff')).to be_a Hash
4
+ describe ".new" do
5
+ it "is a Coderbits::Client.new" do
6
+ expect(Coderbits.new).to be_a Coderbits::Client
8
7
  end
9
8
  end
10
9
 
11
- describe ".glue" do
12
- it "is a Coderbits::Glue" do
13
- expect(Coderbits.glue('artemeff')).to be_a Coderbits::Glue
10
+ describe ".get" do
11
+ it "is a Coderbits::Client.new.get" do
12
+ expect(Coderbits.get('artemeff')).to be_a Hash
14
13
  end
15
14
  end
16
-
17
15
  end
@@ -1,6 +1,2 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
1
  require 'rspec'
5
2
  require 'coderbits'
6
- require 'fileutils'
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderbits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Artemev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-01 00:00:00.000000000 Z
11
+ date: 2013-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: '1.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: faraday
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -38,62 +24,20 @@ dependencies:
38
24
  - - ~>
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0.8'
41
- - !ruby/object:Gem::Dependency
42
- name: faraday_middleware
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '0.8'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '0.8'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: multi_json
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
31
  - - ~>
60
32
  - !ruby/object:Gem::Version
61
- version: '1.7'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '1.7'
69
- - !ruby/object:Gem::Dependency
70
- name: sprite-factory
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: '1.5'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: '1.5'
83
- - !ruby/object:Gem::Dependency
84
- name: chunky_png
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: '1.2'
33
+ version: '1.3'
90
34
  type: :runtime
91
35
  prerelease: false
92
36
  version_requirements: !ruby/object:Gem::Requirement
93
37
  requirements:
94
38
  - - ~>
95
39
  - !ruby/object:Gem::Version
96
- version: '1.2'
40
+ version: '1.3'
97
41
  - !ruby/object:Gem::Dependency
98
42
  name: hashie
99
43
  requirement: !ruby/object:Gem::Requirement
@@ -121,16 +65,12 @@ files:
121
65
  - Rakefile
122
66
  - coderbits.gemspec
123
67
  - lib/coderbits/client.rb
124
- - lib/coderbits/defaults.rb
125
- - lib/coderbits/glue.rb
126
- - lib/coderbits/object.rb
127
68
  - lib/coderbits/version.rb
128
69
  - lib/coderbits.rb
129
70
  - spec/coderbits/client_spec.rb
130
- - spec/coderbits/glue_spec.rb
131
71
  - spec/coderbits_spec.rb
132
72
  - spec/spec_helper.rb
133
- homepage: http://github.com/artemeff/coderbits
73
+ homepage: https://github.com/artemeff/coderbits
134
74
  licenses:
135
75
  - MIT
136
76
  metadata: {}
@@ -156,7 +96,6 @@ specification_version: 4
156
96
  summary: Coderbits API wrapper
157
97
  test_files:
158
98
  - spec/coderbits/client_spec.rb
159
- - spec/coderbits/glue_spec.rb
160
99
  - spec/coderbits_spec.rb
161
100
  - spec/spec_helper.rb
162
101
  has_rdoc:
@@ -1,7 +0,0 @@
1
- module Coderbits
2
- module Defaults
3
- BASE_URL = 'https://coderbits.com' unless defined? Coderbits::Defaults::BASE_URL
4
- HEADERS = { accept: 'application/json' } unless defined? Coderbits::Defaults::HEADERS
5
- SSL = { verify: false } unless defined? Coderbits::Defaults::SSL
6
- end
7
- end
@@ -1,116 +0,0 @@
1
- module Coderbits
2
- class Glue
3
- # valid options
4
- OPTIONS = [
5
- :badge_size, :save_to, :layout, :style, :library, :selector,
6
- :padding, :margin, :nocomments, :output_image, :output_style,
7
- :width, :height
8
- ]
9
-
10
- def initialize username, options = {}
11
- safe options
12
- @username = username
13
- end
14
-
15
- # launching all rockets
16
- def run!
17
- imgs = download_images
18
- css = merge_images
19
- html = generate_html imgs
20
-
21
- {
22
- images: imgs,
23
- css: css,
24
- html: html
25
- }
26
- end
27
-
28
- def download_images
29
- # get user data
30
- data = Coderbits::Client.new.get @username
31
-
32
- # collect images
33
- images = data.badges.select { |b| b.earned }.map { |b| b.image_link.match(/(.*)\/(.*)/)[2] }.uniq
34
-
35
- # create directories
36
- Dir.mkdir @options[:save_to] unless Dir.exists? @options[:save_to]
37
- Dir.mkdir "#{@options[:save_to]}/badges" unless Dir.exists? "#{@options[:save_to]}/badges"
38
-
39
- # connection for download images
40
- connection = Coderbits::Client.new(headers: { accept: 'image/png' }).connection
41
-
42
- # download images
43
- images.each do |img|
44
- # specify badge size
45
- img = change_size img unless @options[:badge_size] == 64
46
-
47
- # download image
48
- begin
49
- response = connection.get "/images/badges/#{img}"
50
-
51
- # save to disk
52
- if response.headers["content-type"] == "image/png"
53
- File.open("#{@options[:save_to]}/badges/#{img.downcase}", 'wb') { |f| f.write response.body }
54
- end
55
- rescue Exception => e
56
- # TODO logging
57
- end
58
- end
59
- end
60
-
61
- # merge and generate css by SpriteFactory
62
- def merge_images
63
- SpriteFactory.run! "#{@options[:save_to]}/badges", @options
64
- end
65
-
66
- def generate_html images
67
- html_tags = []
68
-
69
- images.each do |name|
70
- html_tags << "<img src='#{@options[:output_image]}' class='#{@options[:selector][1..-1]}#{name.downcase.gsub(/.png/,'')}'>"
71
- end
72
-
73
- html_tags.join "\n"
74
- end
75
-
76
- def safe options
77
- # select only allowed options
78
- options = options.select { |k, v| OPTIONS.include? k }
79
-
80
- dflt = {
81
- badge_size: 64, # badges size for download
82
- save_to: '.', # path for files
83
-
84
- layout: 'horizontal', # horizontal, vertical or packed
85
- style: 'css', # css, scss or sass
86
- library: 'chunkypng', # rmagick or chunkypng
87
- selector: '.badge-', # selector
88
- padding: 0, # add padding to each sprite
89
- margin: 0, # add margin to each sprite
90
- nocomments: true # suppress generation of comments in output stylesheet
91
- }
92
-
93
- if options.has_key? :save_to
94
- save_to = options[:save_to]
95
- else
96
- save_to = dflt[:save_to]
97
- end
98
-
99
- dflt[:output_image] = "#{save_to}/badges.png" # output location for generated image
100
- dflt[:output_style] = "#{save_to}/badges.css" # output location for generated stylesheet
101
-
102
- @options = dflt.merge options
103
- end
104
-
105
- private
106
-
107
- def change_size filename
108
- # parse image name
109
- params = filename.match /([A-z\-_]+)(\d+).png/
110
-
111
- # custom badge size
112
- "#{params[1]}#{@options[:badge_size]}.png"
113
- end
114
-
115
- end
116
- end
@@ -1,5 +0,0 @@
1
- module Coderbits
2
- class Object < Hashie::Mash
3
-
4
- end
5
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Coderbits::Glue do
4
-
5
- describe ".new" do
6
- before do
7
- @glue = Coderbits::Glue.new 'artemeff', save_to: './temp/'
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
- after do
17
- FileUtils.rm_rf './temp/'
18
- end
19
-
20
- it "should work" do
21
- Coderbits.glue('artemeff', save_to: './temp/').run!
22
- end
23
-
24
- it "should work with custom badge size" do
25
- Coderbits.glue('artemeff', badge_size: 32, save_to: './temp/').run!
26
- end
27
- end
28
-
29
- describe "#safe" do
30
- before do
31
- @glue = Coderbits::Glue.new 'artemeff'
32
-
33
- @options = {
34
- bad_option: false,
35
- save_to: './'
36
- }
37
- end
38
-
39
- it "should have bad option" do
40
- @options.should include :bad_option
41
- end
42
-
43
- it "should delete bad options" do
44
- safe = @glue.send :safe, @options
45
-
46
- safe.should_not include :bad_option
47
- end
48
- end
49
-
50
- end