awardflair 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.
- data/.gitignore +17 -0
- data/.rvmrc +48 -0
- data/.rvmrc.12.27.2012-19:48:12 +48 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +7 -0
- data/awardflair.gemspec +25 -0
- data/lib/awardflair/pickflair_api.rb +106 -0
- data/lib/awardflair/version.rb +3 -0
- data/lib/awardflair.rb +6 -0
- data/spec/lib/awardflair_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- metadata +114 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@pickflair"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.15.8 (master)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.15.8 (master)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Matt Lally
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Awardflair
|
2
|
+
|
3
|
+
Award flair (badges) to people using your app via the free PickFlair service (http://www.pickflair.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'awardflair'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install awardflair
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
# Connect to your PickFlair account
|
22
|
+
pf = PickFlair.new(api_key, api_secret, application_id)
|
23
|
+
|
24
|
+
# Get a list of all the badges you have created on PickFlair
|
25
|
+
pf.collect_badges
|
26
|
+
|
27
|
+
# If you have already collected badges, this just gets that list again. If you haven't, it collects them for the first time
|
28
|
+
pf.badges
|
29
|
+
|
30
|
+
# Get badge information using badge identifier
|
31
|
+
pf.get_badge_by_identifier(badge_identifier)
|
32
|
+
|
33
|
+
# Find a specific badge that you know you have created using it's name.
|
34
|
+
pf.find_badges("Ruby Ace")
|
35
|
+
|
36
|
+
# Award a badge via a link that you can provide to the recipient
|
37
|
+
ruby_ace_badge = pf.find_badges("Ruby Ace").first # Choosing the first (and probably only) badge you have named "Ruby Ace"
|
38
|
+
ruby_ace_badge.award # Returns a link that you can show to recipient so they can claim the badge.
|
39
|
+
|
40
|
+
# Award a badge by email (also gets you a link that you can give to the user.)
|
41
|
+
first_badge = pf.badges.first # Getting the first badge you created.
|
42
|
+
first_badge.award_to("email_address@mydomain.com")
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/awardflair.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'awardflair/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "awardflair"
|
8
|
+
gem.version = Awardflair::VERSION
|
9
|
+
gem.authors = ["Matt Lally"]
|
10
|
+
gem.email = ["shinsyotta@gmail.com"]
|
11
|
+
gem.description = %q{Award flair (badges) to users of your app using the PickFlair service.}
|
12
|
+
gem.summary = %q{A gem for awarding badges via PickFlair.}
|
13
|
+
gem.homepage = "http://www.awardflair.com"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
|
24
|
+
gem.add_runtime_dependency 'httparty'
|
25
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
# require 'yajl/yajl'
|
3
|
+
|
4
|
+
class PFBadge
|
5
|
+
attr_accessor :id, :name, :description, :picture_url, :pickflair_instance
|
6
|
+
|
7
|
+
def initialize(attributes={})
|
8
|
+
attributes.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value) unless value.nil?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def qualify?(search_terms)
|
14
|
+
search_terms.each do |key, value|
|
15
|
+
if value == self.send(key.to_sym)
|
16
|
+
self
|
17
|
+
else
|
18
|
+
return false && break
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def award
|
24
|
+
pickflair_instance.award_badge(@id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def award_to(email_of_recipient)
|
28
|
+
pickflair_instance.award_badge_by_email(@id, email_of_recipient)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class PickFlair
|
33
|
+
|
34
|
+
include HTTParty
|
35
|
+
attr_accessor :badges
|
36
|
+
|
37
|
+
def initialize(api_key, api_secret, application_id)
|
38
|
+
@badges ||= []
|
39
|
+
self.class.base_uri 'https://www.pickflair.com/api/v1'
|
40
|
+
self.class.default_params :output => 'json'; self.class.format :json
|
41
|
+
@auth = {:api_key => api_key, :api_secret => api_secret, :application_id => application_id}
|
42
|
+
end
|
43
|
+
|
44
|
+
def collect_badges
|
45
|
+
@badges = []
|
46
|
+
array_of_badges_from_api.each do |badge_hash|
|
47
|
+
@badges << PFBadge.new(badge_hash.merge(:pickflair_instance => self))
|
48
|
+
end
|
49
|
+
@badges
|
50
|
+
end
|
51
|
+
|
52
|
+
def badges
|
53
|
+
if @badges.any?
|
54
|
+
@badges
|
55
|
+
else
|
56
|
+
collect_badges
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def find_badges(search_terms)
|
61
|
+
badges.select {|badge| badge.qualify?(search_terms)}
|
62
|
+
end
|
63
|
+
|
64
|
+
def award_badge(badge_identifier)
|
65
|
+
api_response = self.class.post("/badge_request_logs.json", :body => token.merge(:badge_id => badge_identifier))
|
66
|
+
api_response.parsed_response["data"]["badge_awarding_url"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def award_badge_by_email(badge_identifier, email_of_recipient)
|
70
|
+
api_response = self.class.post("/email_awards.json", :body => token.merge(:badge_id => badge_identifier, :email => email_of_recipient))
|
71
|
+
api_response.parsed_response["data"]["badge_award_url"]
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_badge_by_identifier(badge_identifier)
|
75
|
+
badges_that_match = find_badges(:id => badge_identifier)
|
76
|
+
if badges_that_match.any?
|
77
|
+
badges_that_match.first
|
78
|
+
else
|
79
|
+
api_response = self.class.get("/badges/#{badge_identifier}.json", :body => token)
|
80
|
+
api_response.parsed_response["data"]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def login
|
87
|
+
response = self.class.post("/logins.json", :body => @auth)
|
88
|
+
@token = response["data"]["token"]
|
89
|
+
end
|
90
|
+
|
91
|
+
def token
|
92
|
+
{ :token => (@token || login) }
|
93
|
+
end
|
94
|
+
|
95
|
+
def array_of_badges_from_api
|
96
|
+
api_response = self.class.get("/badges.json", :body => token)
|
97
|
+
api_response.parsed_response["data"]["flair"]
|
98
|
+
end
|
99
|
+
|
100
|
+
# def find(search_terms = {})
|
101
|
+
# array_of_badges_from_api.select do |badge_from_api|
|
102
|
+
# badge_from_api[]
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
|
106
|
+
end
|
data/lib/awardflair.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'awardflair'
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awardflair
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Lally
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: httparty
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Award flair (badges) to users of your app using the PickFlair service.
|
63
|
+
email:
|
64
|
+
- shinsyotta@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rvmrc
|
71
|
+
- .rvmrc.12.27.2012-19:48:12
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- awardflair.gemspec
|
77
|
+
- lib/awardflair.rb
|
78
|
+
- lib/awardflair/pickflair_api.rb
|
79
|
+
- lib/awardflair/version.rb
|
80
|
+
- spec/lib/awardflair_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: http://www.awardflair.com
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: -592585161258406128
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: -592585161258406128
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.24
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: A gem for awarding badges via PickFlair.
|
112
|
+
test_files:
|
113
|
+
- spec/lib/awardflair_spec.rb
|
114
|
+
- spec/spec_helper.rb
|