omniauth-etsy 0.0.2.alpha → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,30 +1,81 @@
1
1
  # OmniAuth Etsy
2
2
 
3
- A very alpha and unofficial [OmniAuth](https://github.com/intridea/omniauth) strategy for Etsy. To use it, you'll need OmniAuth and a registered application on [Etsy](https://www.etsy.com/developers/register) to get a token and secret.
3
+ An unofficial [OmniAuth](https://github.com/intridea/omniauth) strategy for Etsy. To use it, you'll need OmniAuth and a registered application on [Etsy](https://www.etsy.com/developers/register).
4
4
 
5
- ## Useage with Rails
5
+ ## Usage
6
6
 
7
- Create an initializer file, and tell OmniAuth you'd like to register etsy as a provider:
7
+ `OmniAuth::Etsy` is Rack middleware. Below are examples written specifically for Rails 3.1+, however it can be used in other frameworks based off of Rack (Sinatra, etc). See the [OmniAuth docs](https://github.com/intridea/omniauth) for detailed usage examples.
8
+
9
+ Create an initializer file, and tell OmniAuth you'd like to register Etsy as a provider:
10
+
11
+ Rails.application.config.middleware.use OmniAuth::Builder do
12
+ provider :etsy, ENV['ETSY_TOKEN'], ENV['ETSY_SECRET']
13
+ end
14
+
15
+ Etsy allows for sandbox API requests; to utilize it add sandbox to your config:
8
16
 
9
17
  Rails.application.config.middleware.use OmniAuth::Builder do
10
- provider :etsy, 'token', 'secret'
18
+ provider :etsy, ENV['ETSY_TOKEN'], ENV['ETSY_SECRET'], :sandbox => true
11
19
  end
12
20
 
13
- Optionally, you may also pass in comma separated [Permission Scopes](http://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes):
21
+ Note: Etsy's sandbox API may return rather _unusual_ results. I advise when making read-only requests to simply forgo the sandbox.
22
+
23
+ Optionally, you may also pass in comma-separated [Permission Scopes](http://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes):
14
24
 
15
25
 
16
26
  Rails.application.config.middleware.use OmniAuth::Builder do
17
- provider :etsy, 'token', 'secret', :scope => 'email_r'
27
+ provider :etsy, ENV['ETSY_TOKEN'], ENV['ETSY_SECRET'], :scope => 'email_r,profile_r,listings_r'
18
28
  end
19
29
 
20
30
  Note: If for some reason you receive a 400 error, it's probably your scopes.
21
31
 
32
+ ## Auth hash
33
+
34
+ On callback this is what you can expect in your `request.env['omniauth.auth']` info hash:
35
+
36
+ ```ruby
37
+ provider: etsy
38
+ uid: 12341241
39
+ info:
40
+ nickname: 'nickname'
41
+ email: 'you@email.com'
42
+ user_id: 12341241
43
+ first_name: 'Bill'
44
+ last_name: 'Clinton'
45
+ name: 'Bill Clinton'
46
+ image: 'http://www.etsy.com/images/avatars/default_avatar_75px.png'
47
+ profile:
48
+ user_profile_id: 12341241
49
+ user_id: 12341241
50
+ login_name: 'nickname'
51
+ bio: ''
52
+ gender: private
53
+ birth_month: '0'
54
+ birth_day: '0'
55
+ birth_year: '0'
56
+ join_tsz: 1337366290
57
+ materials: ''
58
+ country_id: ''
59
+ region: ''
60
+ city: ''
61
+ location: ''
62
+ avatar_id: ''
63
+ lat: ''
64
+ lon: ''
65
+ transaction_buy_count: 0
66
+ transaction_sold_count: 0
67
+ is_seller: false
68
+ image_url_75x75: 'http://www.etsy.com/images/avatars/default_avatar_75px.png'
69
+ first_name: 'Bill'
70
+ last_name: 'Clinton'
71
+ ```
72
+
22
73
  ## Installation
23
74
 
24
75
  Add OmniAuth and OmniAuth::Etsy to your application's Gemfile:
25
76
 
26
77
  gem 'omniauth', '~>1.0'
27
- gem 'omniauth-etsy', '0.0.2.alpha'
78
+ gem 'omniauth-etsy', '~>0.1.0'
28
79
 
29
80
  And then execute:
30
81
 
@@ -32,9 +83,11 @@ And then execute:
32
83
 
33
84
  Or install it yourself as:
34
85
 
35
- $ gem install omniauth
86
+ $ gem install omniauth
36
87
  $ gem install omniauth-etsy
37
88
 
89
+ `OmniAuth::Etsy` has been used on both Ruby 1.9.2 and REE 1.8.7.
90
+
38
91
  ## Contributing
39
92
 
40
93
  1. Fork it
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Etsy
3
- VERSION = "0.0.2.alpha"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -3,8 +3,9 @@ require 'omniauth-oauth'
3
3
  module OmniAuth
4
4
  module Strategies
5
5
  class Etsy < OmniAuth::Strategies::OAuth
6
+
6
7
  option :client_options, {
7
- :site => "http://sandbox.openapi.etsy.com/v2",
8
+ :site => "http://openapi.etsy.com/v2",
8
9
  :request_token_path => "/oauth/request_token",
9
10
  :access_token_path => "/oauth/access_token",
10
11
  :authorize_url => "https://www.etsy.com/oauth/signin"
@@ -17,31 +18,38 @@ module OmniAuth
17
18
  'nickname' => raw_info['login_name'],
18
19
  'email' => raw_info['primary_email'],
19
20
  'user_id' => raw_info['user_id'],
20
- }.merge!(profile_info)
21
+ 'name' => "#{profile_info['first_name']} #{profile_info['last_name']}",
22
+ 'first_name' => profile_info['first_name'],
23
+ 'last_name' => profile_info['last_name'],
24
+ 'image' => profile_info['image_url_75x75'],
25
+ 'profile' => profile_info
26
+ }
21
27
  end
22
28
 
23
29
  def request_phase
24
30
  if options.scope
25
- options.request_params.merge!(:scope => Rack::Utils.build_query([options.scope]))
31
+ options.request_params.merge!(:scope => options.scope.gsub(',', ' '))
26
32
  end
33
+ prep_sandbox
27
34
  super
28
35
  end
29
36
 
30
- def profile_info
31
- profile = user_hash['Profile']
32
- if profile
33
- {
34
- 'first_name' => profile['first_name'],
35
- 'last_name' => profile['last_name'],
36
- 'image' => profile['image_url_75x75'],
37
- 'full_name' => "#{profile['first_name']} #{profile['last_name']}",
38
- 'name' => "#{profile['first_name']} #{profile['last_name']}"
39
- }
40
- else
41
- {}
37
+ def callback_phase
38
+ prep_sandbox
39
+ super
40
+ end
41
+
42
+ def prep_sandbox
43
+ if options.sandbox
44
+ options.client_options.merge!(:site => "http://sandbox.openapi.etsy.com/v2")
42
45
  end
43
46
  end
44
47
 
48
+ def profile_info
49
+ @profile_info ||= user_hash['Profile']
50
+ @profile_info.each { |k,v| @profile_info[k] = '' if v == nil }
51
+ end
52
+
45
53
  def raw_info
46
54
  @data ||= user_hash
47
55
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-etsy
3
3
  version: !ruby/object:Gem::Version
4
- hash: -850052270
5
- prerelease: 6
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- - alpha
11
- version: 0.0.2.alpha
10
+ version: 0.1.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - Jeff Mehlhoff
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2012-05-27 00:00:00 -07:00
18
+ date: 2012-05-28 00:00:00 -07:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -103,14 +102,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
102
  required_rubygems_version: !ruby/object:Gem::Requirement
104
103
  none: false
105
104
  requirements:
106
- - - ">"
105
+ - - ">="
107
106
  - !ruby/object:Gem::Version
108
- hash: 25
107
+ hash: 3
109
108
  segments:
110
- - 1
111
- - 3
112
- - 1
113
- version: 1.3.1
109
+ - 0
110
+ version: "0"
114
111
  requirements: []
115
112
 
116
113
  rubyforge_project: