avatars.io 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'httparty'
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "rdoc", ">= 3.12"
8
+ gem "bundler", ">= 1.0.0"
9
+ gem "jeweler", ">= 1.8.3"
10
+ gem "simplecov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ httparty (0.8.1)
6
+ multi_json
7
+ multi_xml
8
+ jeweler (1.8.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.7.3)
14
+ multi_json (1.0.4)
15
+ multi_xml (0.4.2)
16
+ rake (0.9.2.2)
17
+ rdoc (3.12)
18
+ json (~> 1.4)
19
+ shoulda (2.11.3)
20
+ simplecov (0.5.4)
21
+ multi_json (~> 1.0.3)
22
+ simplecov-html (~> 0.5.3)
23
+ simplecov-html (0.5.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (>= 1.0.0)
30
+ httparty
31
+ jeweler (>= 1.8.3)
32
+ rdoc (>= 3.12)
33
+ shoulda
34
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Vadim Demedes
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.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Avatars.io Ruby client
2
+
3
+ Hosted User Avatar Service for your Apps and Site.
4
+
5
+ # Installation
6
+
7
+ `gem install avatars.io`
8
+
9
+ or
10
+
11
+ ```ruby
12
+ gem 'avatars.io'
13
+ ```
14
+
15
+ in Bundler.
16
+
17
+ # Usage
18
+
19
+ ```ruby
20
+ require 'avatars.io'
21
+
22
+ # Getting links to avatars in social networks
23
+
24
+ avatar_url('twitter', 'vdemedes') # returns 'http://avatars.io/twitter/vdemedes', twitter, instagram and facebook are available
25
+ avatar_url('instagram', 'vdemedes')
26
+ avatar_url('facebook', 'vdemedes')
27
+
28
+ # Uploading own avatars
29
+
30
+ AvatarsIO.client_id = 'your client id'
31
+ AvatarsIO.access_token = 'your access token'
32
+
33
+ AvatarsIO.upload 'path/to/image.jpg' # http://avatars.io/ast3423
34
+
35
+ # with ability to assign custom identifiers
36
+
37
+ AvatarsIO.upload 'path/to/another/image.jpg', 'very-nice-image' # http://avatars.io/23434thfsds7dhfsdf/very-nice-image
38
+ ```
39
+
40
+ # Tests
41
+
42
+ Run tests by executing `rake test` in Terminal.
43
+
44
+ # License
45
+
46
+ MIT.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
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 = "avatars.io"
18
+ gem.homepage = "http://avatars.io"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Hosted User Avatar Service for your Apps and Site}
21
+ gem.description = %Q{Hosted User Avatar Service for your Apps and Site. Load avatars easily from Twitter, Facebook and Instagram or upload your own. }
22
+ gem.email = "sbioko@gmail.com"
23
+ gem.authors = ["Vadim Demedes"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "avatars.io #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/avatars.io.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'digest/md5'
4
+ require 'json'
5
+
6
+ class AvatarsIO
7
+ include HTTParty
8
+ base_uri 'avatars.io'
9
+ format :json
10
+
11
+ @@client_id = ''
12
+ @@access_token = ''
13
+
14
+ def self.client_id=(client_id)
15
+ @@client_id = client_id
16
+ end
17
+
18
+ def self.access_token=(access_token)
19
+ @@access_token = access_token
20
+ end
21
+
22
+ def self.upload(filename, identifier = '')
23
+ file = File.read filename
24
+ response = self.post '/v1/token', {
25
+ :headers => {
26
+ 'x-client_id' => @@client_id,
27
+ 'Authorization' => "OAuth #{ @@access_token }"
28
+ }, :body => {
29
+ :data => {
30
+ :filename => filename,
31
+ :md5 => Digest::MD5::hexdigest(file),
32
+ :size => File.size(filename),
33
+ :path => identifier
34
+ }
35
+ }.to_json
36
+ }
37
+ return response["data"]["url"] if !response["data"]["upload_info"]
38
+
39
+ info = response["data"]["upload_info"]
40
+ AvatarsIOFile.put info["upload_url"].gsub('http://s3.amazonaws.com', ''), {
41
+ :headers => {
42
+ 'Authorization' => info["signature"],
43
+ 'Date' => info["date"],
44
+ 'Content-Type' => info["content_type"],
45
+ 'x-amz-acl' => 'public-read'
46
+ },
47
+ :body => file
48
+ }
49
+
50
+ response = self.post "/v1/token/#{ response["data"]["id"] }/complete", {
51
+ :headers => {
52
+ 'x-client_id' => @@client_id,
53
+ 'Authorization' => "OAuth #{ @@access_token }"
54
+ },
55
+ :body => ''
56
+ }
57
+
58
+ response["data"]
59
+ end
60
+
61
+ def self.avatar_url(service = 'twitter', key)
62
+ "http://avatars.io/#{ service }/#{ key }"
63
+ end
64
+ end
65
+
66
+ def avatar_url(service, key)
67
+ AvatarsIO.avatar_url service, key
68
+ end
69
+
70
+ class AvatarsIOFile
71
+ include HTTParty
72
+ base_uri 's3.amazonaws.com'
73
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'avatars.io'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+
3
+ AvatarsIO.client_id = 'your client id'
4
+ AvatarsIO.access_token = 'your access token'
5
+
6
+ class TestAvatarsIO < Test::Unit::TestCase
7
+ should "upload an avatar" do
8
+ assert_not_nil AvatarsIO.upload('/Users/vadimdemedes/Pictures/Cat.jpg')
9
+ end
10
+
11
+ should "upload an avatar with assigned identifier" do
12
+ assert_not_nil AvatarsIO.upload('/Users/vadimdemedes/Pictures/Building.jpg', 'building')
13
+ end
14
+
15
+ should "return Twitter's avatar URL" do
16
+ assert_equal 'http://avatars.io/twitter/vdemedes', avatar_url('twitter', 'vdemedes')
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avatars.io
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vadim Demedes
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70197165716180 !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: *70197165716180
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &70197165715560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70197165715560
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ requirement: &70197165714760 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '3.12'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70197165714760
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &70197165714160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70197165714160
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70197165713660 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.8.3
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70197165713660
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: &70197165713080 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70197165713080
80
+ description: ! 'Hosted User Avatar Service for your Apps and Site. Load avatars easily
81
+ from Twitter, Facebook and Instagram or upload your own. '
82
+ email: sbioko@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.md
88
+ files:
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - VERSION
95
+ - lib/avatars.io.rb
96
+ - test/helper.rb
97
+ - test/test_avatars.io.rb
98
+ homepage: http://avatars.io
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: -1266404038131215128
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.10
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Hosted User Avatar Service for your Apps and Site
126
+ test_files: []