badges 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c93936af21bbeade438e46a117aed48ef2a9027a
4
+ data.tar.gz: 756a2ddff2b56a85afdb72f48c404ae416f589c6
5
+ SHA512:
6
+ metadata.gz: 282c0be03afe7c89cd1ef4262ad63331a9ef10d9b333173606d44c18e0f97397a79968b8f8b1f1c26a7fe3b6ace5a0133fbd5852a582c5fb66410f2e8f2c4776
7
+ data.tar.gz: 52d11a131b865972e4491f5a1dd7b12af82eda5a20bf11c840be440afc986304446b880dd3d2af80156a61878e3e591ff723283635a84c826fa61afc9631d283
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # ----------
20
+ # My Ignores
21
+ # ----------
22
+
23
+ # Ignore .DS_Store files
24
+ .DS_Store
25
+
26
+ # Ignore ruby configuration files
27
+ /.ruby-version
28
+ /.ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in badges.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Keil Miller Jr
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # Badges
2
+
3
+ Badges is a Ruby gem that allows you to connect to different API's to retrieve your earned badges and profile information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'badges'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install badges
18
+
19
+ ## Requirements
20
+
21
+ * Ruby 1.9.3 or higher
22
+ * httparty
23
+
24
+ ## Usage
25
+
26
+ CodeSchool example:
27
+
28
+ codeschool = Badges::CodeSchool.new('username')
29
+
30
+ codeschool.username
31
+ => "username"
32
+
33
+ codeschool.profile_url
34
+ => "http://www.codeschool.com/users/username"
35
+
36
+ codeschool.avatar_url
37
+ => "http://example.com/avatar.jpg"
38
+
39
+ codeschool.courses_completed
40
+ => [{"title"=>"Course", "url"=>"http://example.com", "badge"=>"http://example.com/badge.png"}]
41
+
42
+ codeschool.courses_completed[0]['title']
43
+ => "Course"
44
+
45
+ codeschool.courses_in_progress
46
+ => [{"title"=>"Course", "url"=>"http://example.com", "badge"=>"http://example.com/badge.png"}]
47
+
48
+ codeschool.member_since
49
+ => "2011-03-22T06:54:21Z"
50
+
51
+ codeschool.total_score
52
+ => "<b>114225</b>"
53
+
54
+ Team Treehouse example:
55
+
56
+ treehouse = Badges::Treehouse.new('profile_name')
57
+
58
+ treehouse.profile_name
59
+ => "profile_name"
60
+
61
+ treehouse.profile_url
62
+ => "http://teamtreehouse.com/profile_name"
63
+
64
+ treehouse.badges
65
+ => [{"id"=>49, "name"=>"Badge", "url"=>"http://example.com", "icon_url"=>"http://example.com/badge.png", "earned_date"=>"2012-09-11T18:41:13Z", "courses"=>[]}]
66
+
67
+ treehouse.badges[0]['name']
68
+ => "Badge"
69
+
70
+ treehouse.gravatar_url
71
+ => "http://example.com/avatar.jpg"
72
+
73
+ treehouse.name
74
+ => "First Last"
75
+
76
+ treehouse.points
77
+ => {"total"=>1740, "html"=>447, "css"=>483, "javascript"=>0, "ruby"=>0, "ios"=>0, "business"=>0, "android"=>0, "php"=>0, "wordpress"=>0, "design"=>180, "dev tools"=>0}
78
+
79
+ treehouse.points_total
80
+ => 1740
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'badges/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'badges'
8
+ spec.version = Badges::VERSION
9
+ spec.authors = ['Keil Miller Jr']
10
+ spec.email = ['keilmillerjr@me.com']
11
+ spec.description = "Badges is a Ruby gem that allows you to connect to different API's to retrieve your earned badges and profile information."
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/keilmillerjr/badges'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+
26
+ spec.add_development_dependency 'httparty'
27
+ end
@@ -0,0 +1,128 @@
1
+ require 'badges/version'
2
+ require 'httparty'
3
+
4
+ module Badges
5
+ class Badge
6
+ include HTTParty
7
+
8
+ private
9
+
10
+ def get(url)
11
+ begin
12
+ JSON.parse HTTParty.get(url).response.body
13
+ rescue
14
+ nil
15
+ end
16
+ end
17
+ end
18
+
19
+ class CodeSchool < Badge
20
+ attr_reader :profile_url, :username
21
+
22
+ def initialize(username)
23
+ @username = username
24
+ @profile_url = 'http://www.codeschool.com/users/' + @username
25
+
26
+ @response = get(@profile_url + '.json')
27
+ end
28
+
29
+ def avatar_url
30
+ begin
31
+ @response['user']['avatar']
32
+ rescue
33
+ nil
34
+ end
35
+ end
36
+
37
+ def badges
38
+ begin
39
+ @response['badges']
40
+ rescue
41
+ nil
42
+ end
43
+ end
44
+
45
+ def courses_completed
46
+ begin
47
+ @response['courses']['completed']
48
+ rescue
49
+ nil
50
+ end
51
+ end
52
+
53
+ def courses_in_progress
54
+ begin
55
+ @response['courses']['in_progress']
56
+ rescue
57
+ nil
58
+ end
59
+ end
60
+
61
+ def member_since
62
+ begin
63
+ @response['user']['member_since']
64
+ rescue
65
+ nil
66
+ end
67
+ end
68
+
69
+ def total_score
70
+ begin
71
+ @response['user']['total_score']
72
+ rescue
73
+ nil
74
+ end
75
+ end
76
+ end
77
+
78
+ class Treehouse < Badge
79
+ attr_reader :profile_name, :profile_url
80
+
81
+ def initialize(profile_name)
82
+ @profile_name = profile_name
83
+ @profile_url = 'http://teamtreehouse.com/' + @profile_name
84
+
85
+ @response = get(@profile_url + '.json')
86
+ end
87
+
88
+ def badges
89
+ begin
90
+ @response['badges']
91
+ rescue
92
+ nil
93
+ end
94
+ end
95
+
96
+ def gravatar_url
97
+ begin
98
+ @response['gravatar_url']
99
+ rescue
100
+ nil
101
+ end
102
+ end
103
+
104
+ def name
105
+ begin
106
+ @response['name']
107
+ rescue
108
+ nil
109
+ end
110
+ end
111
+
112
+ def points
113
+ begin
114
+ @response['points']
115
+ rescue
116
+ nil
117
+ end
118
+ end
119
+
120
+ def points_total
121
+ begin
122
+ @response['points']['total']
123
+ rescue
124
+ nil
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,3 @@
1
+ module Badges
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: badges
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keil Miller Jr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-06 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
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
+ description: Badges is a Ruby gem that allows you to connect to different API's to
56
+ retrieve your earned badges and profile information.
57
+ email:
58
+ - keilmillerjr@me.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - badges.gemspec
69
+ - lib/badges.rb
70
+ - lib/badges/version.rb
71
+ homepage: https://github.com/keilmillerjr/badges
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 1.9.3
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Badges is a Ruby gem that allows you to connect to different API's to retrieve
95
+ your earned badges and profile information.
96
+ test_files: []