avataree 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.3
@@ -23,28 +23,76 @@
23
23
 
24
24
  require 'digest/md5'
25
25
 
26
- module Helper
26
+ module Avataree
27
+ module Helper
27
28
 
28
- class << self
29
- attr_accessor :secure_url_services, :url_services
30
- end
29
+ class << self
30
+ attr_accessor :secure_url_services, :url_services
31
+ end
31
32
 
32
- def self.included(base)
33
- self.secure_url_services = "https://secure.gravatar.com/"
34
- self.url_services = "http://www.gravatar.com/"
35
- end
33
+ def self.included(base)
34
+ self.secure_url_services = "https://secure.gravatar.com/"
35
+ self.url_services = "http://www.gravatar.com/"
36
+ MonkeyPatches.activate!
37
+ end
36
38
 
37
- #makes MD5 hash of given email
38
- def make_digest(email)
39
- Digest::MD5.hexdigest(email)
40
- end
39
+ #makes MD5 hash of given email
40
+ def make_digest(email)
41
+ Digest::MD5.hexdigest(email)
42
+ end
41
43
 
42
- #fallback method if not defined(i.e if not used with rails)
43
- #to_param for hash if hash does not respond to it
44
- Hash.class_eval do
45
- def to_param
46
- self.collect{|k,v| "#{k}=#{v}"}.join("&")
47
- end unless Hash.respond_to?(:to_param)
48
- end
44
+ def self.url_for_request(ssl = false)
45
+ ssl ? self.secure_url_services : self.url_services
46
+ end
47
+
48
+ def prepare_url_with_params(url, options)
49
+ [url, get_params(options)].compact.join("?")
50
+ end
51
+
52
+ def get_params(options)
53
+ options.to_param.presence
54
+ end
49
55
 
56
+ #fallback method if not defined(i.e if not used with rails)
57
+ #to_param for hash if hash does not respond to it
58
+ Hash.class_eval do
59
+ def to_param
60
+ self.collect{|k,v| "#{k}=#{v}"}.join("&")
61
+ end unless Hash.respond_to?(:to_param)
62
+ end
63
+
64
+ module MonkeyPatches
65
+
66
+ def self.activate!
67
+ Hash.send(:include, MonkeyHash)
68
+ Object.send(:include, MonkeyObject)
69
+ end
70
+
71
+ module MonkeyHash
72
+
73
+ #monkey patch for hash
74
+ def to_param
75
+ self.collect{|k,v| "#{k}=#{v}"}.join("&")
76
+ end unless Hash.respond_to?(:to_param)
77
+
78
+ end
79
+
80
+ module MonkeyObject
81
+
82
+ def blank?
83
+ instance_of? Array ? empty? : nil?
84
+ end unless Object.respond_to?(:blank?)
85
+
86
+ def present?
87
+ !blank?
88
+ end unless Object.respond_to?(:present?)
89
+
90
+ def presence
91
+ present? ? self : nil
92
+ end unless Object.respond_to?(:presence)
93
+
94
+ end
95
+ end
96
+
97
+ end
50
98
  end
@@ -25,7 +25,7 @@ module Avataree
25
25
 
26
26
  module ImageServices
27
27
 
28
- include Helper
28
+ include Avataree::Helper
29
29
 
30
30
  #this method returns resulted path to be requested to gravatar. takes all argument as a hash
31
31
  #options:
@@ -50,11 +50,10 @@ module Avataree
50
50
 
51
51
  def gravatar_image_path(email, options = {})
52
52
  email = make_digest(email)
53
- services_url = (options[:secure] ? Helper.secure_url_services : Helper.url_services) and options.delete(:secure)
54
- email<<".#{options[:extension]}" and options.delete(:extension) if options[:extension]
55
- params = options.to_param unless options.empty?
53
+ services_url = Helper.url_for_request(options.delete(:secure))
54
+ email<<".#{options.delete(:extension)}" if options[:extension]
56
55
  resulted_path = [services_url, "avatar/", email].join("")
57
- [resulted_path, params].compact.join("?")
56
+ prepare_url_with_params(resulted_path, options)
58
57
  end
59
58
  alias_method :gravatar, :gravatar_image_path
60
59
 
@@ -28,6 +28,8 @@ module Avataree
28
28
 
29
29
  module ProfileServices
30
30
 
31
+ include Avataree::Helper
32
+
31
33
  #options:
32
34
  # <tt>secure</tt> takes boolean values to use https or not :default => false
33
35
  # this method returns hash full of information provided by Gravatar.
@@ -40,12 +42,11 @@ module Avataree
40
42
  # Personal Links
41
43
  # Image (main Gravatar)
42
44
  def gravatar_profile(email, options = {})
43
- services_url = (options[:secure] ? Helper.secure_url_services : Helper.url_services) and options.delete(:secure)
45
+ services_url = Helper.url_for_request(options.delete(:secure))
44
46
  email = make_digest(email)
45
47
  email << ".json"
46
- params = options.to_param unless options.empty?
47
48
  resulted_path = [services_url, email].join
48
- path = [resulted_path, params].compact.join("?")
49
+ path = prepare_url_with_params(resulted_path, options)
49
50
  begin
50
51
  JSON.parse(open(path).read)
51
52
  rescue => e
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2010 [Bagwan Pankaj]
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.
21
+
1
22
  # encoding: utf-8
2
23
 
3
24
  require 'avataree'
@@ -1,3 +1,24 @@
1
+ # Copyright (c) 2010 [Bagwan Pankaj]
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.
21
+
1
22
  module Avataree
2
23
 
3
24
  class << self
data/lib/avataree.rb CHANGED
@@ -27,8 +27,13 @@ else
27
27
  require 'avataree/helper'
28
28
  require 'avataree/image'
29
29
  require 'avataree/profile'
30
- # require 'avataree/switch'
31
30
  end
32
31
 
33
32
  module Avataree
33
+
34
+ #gem version
35
+ def self.version #:nodoc
36
+ "v" + File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
37
+ end
38
+
34
39
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avataree
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bagwan Pankaj (a.k.a modulo9)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-18 00:00:00 +05:30
18
+ date: 2011-01-23 00:00:00 +05:30
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -120,13 +120,14 @@ extra_rdoc_files:
120
120
  - LICENSE.txt
121
121
  - README.textile
122
122
  files:
123
+ - LICENSE.txt
124
+ - VERSION
123
125
  - lib/avataree.rb
124
126
  - lib/avataree/helper.rb
125
127
  - lib/avataree/image.rb
126
128
  - lib/avataree/profile.rb
127
129
  - lib/avataree/railtie.rb
128
130
  - lib/avataree/switch.rb
129
- - LICENSE.txt
130
131
  - README.textile
131
132
  - spec/avataree_spec.rb
132
133
  - spec/spec_helper.rb