byline 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm 1.9.2@rails3
2
+
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "rest-client"
7
+ gem "simple_record"
8
+ gem "activemodel"
9
+ gem "json"
10
+
11
+ # Add dependencies to develop your gem here.
12
+ # Include everything needed to run rake, tests, features, etc.
13
+ group :development do
14
+ gem "rspec", "~> 2.3.0"
15
+ gem "jeweler", "~> 1.6.0"
16
+ gem "rcov", ">= 0"
17
+ end
@@ -0,0 +1,69 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.9)
9
+ addressable (2.2.6)
10
+ aws (2.5.3)
11
+ http_connection
12
+ uuidtools
13
+ xml-simple
14
+ builder (2.1.2)
15
+ concur (0.0.8)
16
+ em-http-request
17
+ eventmachine
18
+ faraday
19
+ diff-lcs (1.1.2)
20
+ em-http-request (0.3.0)
21
+ addressable (>= 2.0.0)
22
+ escape_utils
23
+ eventmachine (>= 0.12.9)
24
+ escape_utils (0.2.3)
25
+ eventmachine (0.12.10)
26
+ faraday (0.7.0)
27
+ addressable (~> 2.2.4)
28
+ multipart-post (~> 1.1.0)
29
+ rack (>= 1.1.0, < 2)
30
+ git (1.2.5)
31
+ http_connection (1.4.1)
32
+ i18n (0.5.0)
33
+ jeweler (1.6.4)
34
+ bundler (~> 1.0)
35
+ git (>= 1.2.5)
36
+ rake
37
+ json (1.7.5)
38
+ mime-types (1.16)
39
+ multipart-post (1.1.2)
40
+ rack (1.2.3)
41
+ rake (0.9.2)
42
+ rcov (0.9.9)
43
+ rest-client (1.6.7)
44
+ mime-types (>= 1.16)
45
+ rspec (2.3.0)
46
+ rspec-core (~> 2.3.0)
47
+ rspec-expectations (~> 2.3.0)
48
+ rspec-mocks (~> 2.3.0)
49
+ rspec-core (2.3.1)
50
+ rspec-expectations (2.3.0)
51
+ diff-lcs (~> 1.1.2)
52
+ rspec-mocks (2.3.0)
53
+ simple_record (2.1.6)
54
+ aws
55
+ concur
56
+ uuidtools (2.1.2)
57
+ xml-simple (1.0.16)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ activemodel
64
+ jeweler (~> 1.6.0)
65
+ json
66
+ rcov
67
+ rest-client
68
+ rspec (~> 2.3.0)
69
+ simple_record
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Rune Myrland
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,19 @@
1
+ = byline
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to byline
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Rune Myrland. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "byline"
18
+ gem.homepage = "http://github.com/epubify/byline"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Store user info in Amazon SimpleDB}
21
+ gem.description = %Q{Bio and photo is fetched from gravatar.com}
22
+ gem.email = "rune@epubify.com"
23
+ gem.authors = ["Rune Myrland"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "byline #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,27 @@
1
+ require 'active_model'
2
+ require 'simple_record'
3
+
4
+ class Byline < SimpleRecord::Base
5
+ has_strings :nick, :name, :email
6
+
7
+
8
+ def bio
9
+ gravatar.about_me
10
+ end
11
+
12
+
13
+ def thumbnail_url
14
+ gravatar.thumbnail_url
15
+ end
16
+
17
+
18
+ def photo_url size
19
+ gravatar.photo_url(size)
20
+ end
21
+
22
+
23
+ private
24
+ def gravatar
25
+ @gravatar ||= Gravatar.new(email)
26
+ end
27
+ end
@@ -0,0 +1,66 @@
1
+ require 'httparty'
2
+ require 'restclient'
3
+ require 'digest/md5'
4
+ require 'json'
5
+
6
+ class Gravatar
7
+ class GravatarException < StandardError; end
8
+
9
+ def self.find_by_email email
10
+ self.new(email)
11
+ end
12
+
13
+
14
+ def initialize email
15
+ digest = Digest::MD5.hexdigest(email)
16
+ @gravatar_hash = digest
17
+ end
18
+
19
+
20
+ def gravatar_profile
21
+ @gravatar_profile ||= get_gravatar_profile(@gravatar_hash)
22
+ end
23
+
24
+
25
+ def thumbnail_url
26
+ "http://gravatar.com/avatar/#{@gravatar_hash}.png?d=monsterid"
27
+ end
28
+
29
+
30
+ def photo_url size
31
+ "http://gravatar.com/avatar/#{@gravatar_hash}.png?size=#{size}"
32
+ end
33
+
34
+
35
+ def about_me
36
+ gravatar_profile && gravatar_profile['aboutMe']
37
+ end
38
+
39
+
40
+ def name
41
+ gravatar_profile && gravatar_profile['name']['formatted']
42
+ end
43
+
44
+
45
+ def display_name
46
+ gravatar_profile && gravatar_profile['displayName']
47
+ end
48
+
49
+
50
+ private
51
+ def get_gravatar_profile gravatar_hash
52
+ url = "http://nb.gravatar.com/#{gravatar_hash}.json"
53
+ res = RestClient.get(url)
54
+
55
+ case res.code
56
+ when 200 # Net::HTTPOK
57
+ json = JSON.parse(res.body)
58
+ json && json['entry'] && json['entry'][0] || nil
59
+ when 404 #Net::HTTPNotFound
60
+ nil
61
+ else
62
+ raise res.inspect
63
+ raise GravatarException.new("Could not fetch profile from gravatar.com")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+
8
+ require "models/gravatar"
9
+ require "yaml"
10
+ require "securerandom"
11
+
12
+
13
+ CONFIG_FILE = "#{ENV['HOME']}/.byline_rc"
14
+
15
+
16
+ def connect
17
+ require "models/byline"
18
+
19
+ config = YAML::load(File.read(CONFIG_FILE))
20
+ puts config.inspect
21
+ server, id, key = config["simpledb_server"], config["simpledb_key_id"], config["simpledb_key"]
22
+ puts server, id, key
23
+
24
+ @connection ||= SimpleRecord.establish_connection(id, key, :connection_mode => :single, :server => server)
25
+ end
26
+
27
+
28
+ def help
29
+ puts "byline add 'Username <email@examle.com>'"
30
+ puts "byline find 'email@examle.com'"
31
+ puts "byline destroy 'id'"
32
+ end
33
+
34
+ if ARGV.length == 0
35
+ help
36
+ exit
37
+ end
38
+
39
+
40
+ if ARGV.length == 1
41
+ byline = Gravatar.find_by_email(ARGV[0])
42
+ puts byline.name || byline.display_name
43
+ puts byline.about_me
44
+ exit
45
+ end
46
+
47
+
48
+ case ARGV[0]
49
+ when "help"
50
+ help
51
+ when "add"
52
+ name = ARGV[1].split("<")[0].strip
53
+ email = ARGV[1].split("<")[-1].split(">")[0].strip
54
+ nick = ARGV[2] || SecureRandom.hex(8)
55
+ connect
56
+ byline = Byline.new
57
+ byline.name = name
58
+ byline.email = email
59
+ byline.nick = nick
60
+ byline.save
61
+ when "update"
62
+ name = ARGV[1].split("<")[0].strip
63
+ email = ARGV[1].split("<")[-1].split(">")[0].strip
64
+ nick = ARGV[2]
65
+ connect
66
+ byline = Byline.find_by_email(email)
67
+ byline.name = name
68
+ byline.nick = nick
69
+ byline.save
70
+ when "find"
71
+ connect
72
+ byline = Byline.find_by_email(ARGV[1])
73
+ puts
74
+ puts "#{byline.id} #{byline.attributes["name"][0]} <#{byline.attributes["email"][0]}>"
75
+ puts byline.bio
76
+ puts byline.photo_url(256)
77
+ when "destroy"
78
+ connect
79
+ id = ARGV[1]
80
+ byline = Byline.find(id)
81
+ byline.destroy
82
+ when "all"
83
+ connect
84
+ records = Byline.find(:all)
85
+ puts records.inspect
86
+ records.each do |r|
87
+ puts r.id
88
+ end
89
+ when "destroy_all"
90
+ connect
91
+ Byline.destroy_all
92
+ when "login"
93
+ server, id, key = ARGV[1..3]
94
+ config = {}
95
+ config["simpledb_server"] = server
96
+ config["simpledb_key_id"] = id
97
+ config["simpledb_key"] = key
98
+ File.open(CONFIG_FILE, "w") { |f| f.write config.to_yaml }
99
+ else
100
+ puts "Unkown command: " + ARGV[0]
101
+ end
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "byline"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rune Myrland"]
12
+ s.date = "2012-10-30"
13
+ s.description = "Bio and photo is fetched from gravatar.com"
14
+ s.email = "rune@epubify.com"
15
+ s.executables = ["byline"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ ".rvmrc",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "app/models/byline.rb",
31
+ "app/models/gravatar.rb",
32
+ "bin/byline",
33
+ "byline.gemspec",
34
+ "lib/byline.rb",
35
+ "spec/byline_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = "http://github.com/epubify/byline"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.17"
42
+ s.summary = "Store user info in Amazon SimpleDB"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
49
+ s.add_runtime_dependency(%q<simple_record>, [">= 0"])
50
+ s.add_runtime_dependency(%q<activemodel>, [">= 0"])
51
+ s.add_runtime_dependency(%q<json>, [">= 0"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<rest-client>, [">= 0"])
57
+ s.add_dependency(%q<simple_record>, [">= 0"])
58
+ s.add_dependency(%q<activemodel>, [">= 0"])
59
+ s.add_dependency(%q<json>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<rest-client>, [">= 0"])
66
+ s.add_dependency(%q<simple_record>, [">= 0"])
67
+ s.add_dependency(%q<activemodel>, [">= 0"])
68
+ s.add_dependency(%q<json>, [">= 0"])
69
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
71
+ s.add_dependency(%q<rcov>, [">= 0"])
72
+ end
73
+ end
74
+
@@ -0,0 +1,13 @@
1
+ require 'active_model'
2
+ require 'simple_record'
3
+
4
+ module BylineEngine
5
+ class Engine < Rails::Engine
6
+
7
+ initializer 'simpledb connection' do |app|
8
+ SimpleRecord.establish_connection(ENV['SIMPLEDB_KEY_ID'], ENV['SIMPLEDB_KEY'], :connection_mode => :per_thread, :server => ENV['SIMPLEDB_SERVER'])
9
+ end
10
+
11
+ end
12
+ end
13
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Byline" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'byline'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: byline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rune Myrland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: &80121910 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *80121910
25
+ - !ruby/object:Gem::Dependency
26
+ name: simple_record
27
+ requirement: &80121510 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *80121510
36
+ - !ruby/object:Gem::Dependency
37
+ name: activemodel
38
+ requirement: &80120950 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *80120950
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: &80120540 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *80120540
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &80120050 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *80120050
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &80119530 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *80119530
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &80119130 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *80119130
91
+ description: Bio and photo is fetched from gravatar.com
92
+ email: rune@epubify.com
93
+ executables:
94
+ - byline
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.rdoc
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - .rvmrc
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - app/models/byline.rb
110
+ - app/models/gravatar.rb
111
+ - bin/byline
112
+ - byline.gemspec
113
+ - lib/byline.rb
114
+ - spec/byline_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: http://github.com/epubify/byline
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: 733027439
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.17
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: Store user info in Amazon SimpleDB
144
+ test_files: []