coderbits 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37c520a44bcd474cb90e596f57d2b01f1bc85c50
4
+ data.tar.gz: fd5aacad09bb37015e0415525e76ca362d495f44
5
+ SHA512:
6
+ metadata.gz: 9e49f64390054b1c8bdbdcb909e2ca468b830e3592157da613a690abb9f020f9c4682f4128bbd3b553bd1297b82f9a6839672f4b92965e43a6ff3455fc4c94af
7
+ data.tar.gz: 5d53b23a39b2a5426a9e7528ea0bcceaf4471cee7a35e3065532e862cb5dd2852db9471773392580f36c3a39a53b858cce29009e9c906d30481c9dcdad435b8a
@@ -0,0 +1,3 @@
1
+ ### 0.0.1
2
+
3
+ * Initial
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 artemeff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ # coderbits
2
+
3
+ [![Dependency Status](https://gemnasium.com/artemeff/coderbits.png)](https://gemnasium.com/artemeff/coderbits)
4
+
5
+ Simple wrapper for the Coderbits API
6
+
7
+ ### Install
8
+
9
+ gem install coderbits
10
+
11
+ ### Usage
12
+
13
+ ```ruby
14
+ require 'coderbits'
15
+ ```
16
+
17
+ ### Options
18
+
19
+ ```ruby
20
+
21
+ ```
22
+
23
+ ### Copyright
24
+
25
+ Copyright (c) 2012 Yuri Artemev. See LICENSE.txt for further details.
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new :spec
4
+
5
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "coderbits/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "coderbits"
7
+ s.version = Colos::VERSION
8
+ s.authors = ["Yuri Artemev"]
9
+ s.email = ["i@artemeff.com"]
10
+ s.homepage = "http://github.com/artemeff/coderbits"
11
+ s.description = %q{Simple wrapper for the Coderbits API}
12
+ s.summary = %q{Coderbits API wrapper}
13
+ s.files = %w(CHANGELOG.md README.md LICENSE Rakefile coderbits.gemspec)
14
+ s.files += Dir.glob("lib/**/*.rb")
15
+ s.files += Dir.glob("spec/**/*")
16
+ s.licenses = ['MIT']
17
+ s.require_paths = ['lib']
18
+ s.test_files = Dir.glob("spec/**/*")
19
+
20
+ s.add_development_dependency 'bundler', '~> 1.0'
21
+ s.add_dependency 'faraday', '~> 0.8'
22
+ s.add_dependency 'multi_json', '~> 1.3'
23
+ s.add_dependency 'sprite-factory', '~> 1.5'
24
+ s.add_dependency 'chunky_png', '~> 1.2'
25
+ end
@@ -0,0 +1,27 @@
1
+ require 'coderbits/client'
2
+ require 'coderbits/glue'
3
+
4
+ module Coderbits
5
+ class << self
6
+ # Alias for Coderbits::Client.new
7
+ #
8
+ # @return [Coderbits::Client]
9
+ def new username, options = {}
10
+ Coderbits::Client.new# username, options
11
+ end
12
+
13
+ # Alias for Coderbits::Client.new(...).get
14
+ #
15
+ # @return [Hash]
16
+ def get username
17
+ Coderbits::Client.new.get username
18
+ end
19
+
20
+ # Alias for Coderbits::Glue.new(...)
21
+ #
22
+ # @return
23
+ def glue username, options = {}
24
+ Coderbits::Glue.new username, options
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ module Coderbits
5
+ class Client
6
+ # valid options
7
+ OPTIONS = [:account, :callback]
8
+
9
+ # connection
10
+ attr_reader :connection
11
+
12
+ # Coderbits::Client.new
13
+ #
14
+ # @return @connection
15
+ def initialize
16
+ @connection = Faraday.new url: "https://coderbits.com"
17
+ end
18
+
19
+ # Coderbits::Client.new.get username: 'artemeff'
20
+ def get username, options = {}
21
+ response = @connection.get "/#{username}.json", safe(options)
22
+
23
+ if options[:callback]
24
+ response.body
25
+ else
26
+ MultiJson.load response.body, symbolize_keys: true
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def safe options
33
+ options.select { |k, v| OPTIONS.include? k }
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,102 @@
1
+ require 'sprite_factory'
2
+ require 'faraday'
3
+
4
+ module Coderbits
5
+ class Glue
6
+ # valid options
7
+ OPTIONS = [
8
+ :badge_size, :save_to, :layout, :style, :library, :selector,
9
+ :padding, :margin, :nocomments, :output_image, :output_style,
10
+ :width, :height
11
+ ]
12
+
13
+ def initialize username, options = {}
14
+ safe options
15
+ @username = username
16
+ end
17
+
18
+ def run!
19
+ imgs = download_images
20
+ css = merge_images
21
+ html = generate_html
22
+
23
+ {
24
+ images: imgs,
25
+ css: css,
26
+ html: html
27
+ }
28
+ end
29
+
30
+ def download_images
31
+ # get user data
32
+ data = Coderbits::Client.new.get @username
33
+
34
+ # collect images
35
+ images = data[:badges].select{ |b| b[:earned] }.map { |b| b[:image_link].match(/(.*)\/(.*)/)[2] }.uniq
36
+
37
+ # get connection
38
+ connection = Coderbits::Client.new.connection
39
+
40
+ # create directory
41
+ Dir.mkdir @options[:save_to] unless Dir.exists? @options[:save_to]
42
+ Dir.mkdir "#{@options[:save_to]}/badges" unless Dir.exists? "#{@options[:save_to]}/badges"
43
+
44
+ # download images
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
+
54
+ # download image
55
+ response = connection.get("https://coderbits.com/images/badges/#{img}")
56
+
57
+ # save to disk
58
+ if response.headers["content-type"] == "image/png"
59
+ File.open("#{@options[:save_to]}/badges/#{img}", 'wb') { |f| f.write response.body }
60
+ end
61
+ end
62
+ end
63
+
64
+ 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
71
+ end
72
+
73
+ def generate_html
74
+ nil # coming soon
75
+ end
76
+
77
+ def safe options
78
+ #
79
+ options = options.select { |k, v| OPTIONS.include? k }
80
+
81
+ 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
92
+ }
93
+
94
+ dflt[:output_image] = "#{dflt[:save_to]}/badges.png" # output location for generated image
95
+ dflt[:output_style] = "#{dflt[:save_to]}/badges.css" # output location for generated stylesheet
96
+ dflt[:width] = dflt[:badge_size] # fix width of each sprite to a specific size
97
+ dflt[:height] = dflt[:badge_size] # fix height of each sprite to a specific size
98
+
99
+ @options = dflt.merge options
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ class Colos
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe Coderbits do
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"
24
+ end
25
+ end
26
+
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"]
34
+ end
35
+ end
36
+
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"
44
+ end
45
+ end
46
+
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
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'coderbits'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coderbits
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuri Artemev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-21 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sprite-factory
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: chunky_png
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ description: Simple wrapper for the Coderbits API
84
+ email:
85
+ - i@artemeff.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - README.md
92
+ - LICENSE
93
+ - Rakefile
94
+ - coderbits.gemspec
95
+ - lib/coderbits/client.rb
96
+ - lib/coderbits/glue.rb
97
+ - lib/coderbits/version.rb
98
+ - lib/coderbits.rb
99
+ - spec/coderbits_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: http://github.com/artemeff/coderbits
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Coderbits API wrapper
125
+ test_files:
126
+ - spec/coderbits_spec.rb
127
+ - spec/spec_helper.rb
128
+ has_rdoc: