activeresource-google_spreadsheets 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- metadata.gz: b119d39d25f74629960b194a0fd970d318827306e8550f9a8617960dfd6d5ee7e53498392bc10e81cb1656493530a456d0dbc74610f856ac097f5e776549b589
4
- data.tar.gz: ff1e75731d04d348c0226bec429e07c3fa166bac1189f2c101c7e8bd3d0706f8456a0926d570fcad07f6ca429f663dfa944c2d1952ac4fa101f94961735709e9
5
- SHA1:
6
- metadata.gz: 64ad00bff2d0f3ef59dd5550c7f7d3cac7bd1de5
7
- data.tar.gz: f3b47cc9aac71521e198234b6915b31c43cee641
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59691c2bd7817f25d8065105e5b357aee2506080
4
+ data.tar.gz: 4d3ae79b0a0bb0e9f6120de3507ce1cd2d82eb3b
5
+ SHA512:
6
+ metadata.gz: b47e0295e67c174828bb4bffbf66bd3623d89cd650c89f04bbca2596522065ada1f5ab18375f69f84e95b75b2a46b8e0101f1ec8549ed939c565be81f07a5f1f
7
+ data.tar.gz: 587b14efafcc01ebcff5cfdc88e290b025407598ddab283a7303bfa00a25aa04ad73daee92bda425ce5343dbde49ca330f216d3a60ca674a484364314eb540fb
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'activeresource'
22
22
  spec.add_dependency 'activesupport'
23
+ spec.add_dependency 'google-api-client'
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.3"
25
26
  spec.add_development_dependency "rake"
@@ -0,0 +1,35 @@
1
+ require 'google/api_client'
2
+ require 'openssl'
3
+
4
+ module GoogleSpreadsheets
5
+ module Auth
6
+ class ServiceAccountsAccessToken
7
+ def initialize(options = {})
8
+ @options = options.reverse_merge(
9
+ application_name: 'Ruby',
10
+ token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
11
+ audience: 'https://accounts.google.com/o/oauth2/token',
12
+ scope: 'https://spreadsheets.google.com/feeds/'
13
+ )
14
+ end
15
+
16
+ def call(connection)
17
+ # cf. http://d.hatena.ne.jp/sugyan/20130112/1357996092
18
+ @client ||= Google::APIClient.new(application_name: @options[:application_name]).tap do |c|
19
+ c.authorization = Signet::OAuth2::Client.new(
20
+ token_credential_uri: @options[:token_credential_uri],
21
+ audience: @options[:audience],
22
+ scope: @options[:scope],
23
+ issuer: @options[:client_email],
24
+ signing_key: OpenSSL::PKey::RSA.new(@options[:private_key_pem])
25
+ )
26
+ c.authorization.fetch_access_token!
27
+ end
28
+ if @client.authorization.expired?
29
+ @client.authorization.refresh!
30
+ end
31
+ @client.authorization.access_token
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module GoogleSpreadsheets
2
+ module Auth
3
+ autoload :ServiceAccountsAccessToken, 'google_spreadsheets/auth/service_accounts_access_token'
4
+ end
5
+ end
@@ -1,20 +1,53 @@
1
1
  module GoogleSpreadsheets
2
2
  class Base < ActiveResource::Base
3
- self.site = 'http://spreadsheets.google.com/'
3
+ self.site = 'https://spreadsheets.google.com/'
4
4
  self.format = GDataFormat.new
5
5
 
6
6
  class << self
7
+ # Avoid dup & freeze
8
+ def password
9
+ if defined?(@password)
10
+ @password
11
+ elsif superclass != Object && superclass.password
12
+ superclass.password
13
+ end
14
+ end
15
+
16
+ # Inherit from superclass
17
+ def auth_type
18
+ if defined?(@auth_type)
19
+ @auth_type
20
+ elsif superclass != Object && superclass.auth_type
21
+ superclass.auth_type
22
+ end
23
+ end
24
+
25
+ def access_token=(access_token)
26
+ self.password = access_token
27
+ end
28
+
29
+ def access_token(&block)
30
+ if block_given?
31
+ self.password = block
32
+ else
33
+ password
34
+ end
35
+ end
36
+
7
37
  def connection(refresh = false)
8
38
  if defined?(@connection) || self == Base
9
39
  @connection = Connection.new(site, format) if refresh || @connection.nil?
40
+ @connection.proxy = proxy if proxy
10
41
  @connection.user = user if user
11
42
  @connection.password = password if password
43
+ @connection.auth_type = auth_type if auth_type
12
44
  @connection.timeout = timeout if timeout
13
45
  @connection
14
46
  else
15
47
  superclass.connection
16
48
  end
17
49
  end
50
+
18
51
  def element_path(id, prefix_options = {}, query_options = nil)
19
52
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
20
53
  "/feeds/#{collection_name}#{prefix(prefix_options)}#{id}#{query_string(query_options)}"
@@ -1,8 +1,20 @@
1
1
  module GoogleSpreadsheets
2
2
  class Connection < ActiveResource::Connection
3
- DEBUG = false
4
3
  def authorization_header(http_method, uri)
5
- if @user && @password && !@token
4
+ if auth_type == :bearer
5
+ { 'Authorization' => "Bearer #{access_token}" }
6
+ else
7
+ client_login_authorization_header(http_method, uri)
8
+ end
9
+ end
10
+
11
+ def access_token
12
+ @password.respond_to?(:call) ? @password.call(self) : @password
13
+ end
14
+
15
+ # Deprecated and Not recommended
16
+ def client_login_authorization_header(http_method, uri)
17
+ if @user && @password && !@auth_token
6
18
  email = CGI.escape(@user)
7
19
  password = CGI.escape(@password)
8
20
  http = Net::HTTP.new('www.google.com', 443)
@@ -12,10 +24,15 @@ module GoogleSpreadsheets
12
24
  "accountType=HOSTED_OR_GOOGLE&Email=#{email}&Passwd=#{password}&service=wise",
13
25
  { 'Content-Type' => 'application/x-www-form-urlencoded' })
14
26
  handle_response(resp)
15
- @token = (data || resp.body)[/Auth=(.*)/n, 1]
27
+ @auth_token = (data || resp.body)[/Auth=(.*)/n, 1]
16
28
  end
17
- @token ? { 'Authorization' => "GoogleLogin auth=#{@token}" } : {}
29
+ @auth_token ? { 'Authorization' => "GoogleLogin auth=#{@auth_token}" } : {}
30
+ end
31
+
32
+ private
33
+ def legitimize_auth_type(auth_type)
34
+ auth_type = auth_type.to_sym
35
+ auth_type.in?([:basic, :digest, :bearer]) ? auth_type : :basic
18
36
  end
19
- def http() http = super; http.set_debug_output($stderr) if DEBUG; http end
20
37
  end
21
38
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleSpreadsheets
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -16,6 +16,7 @@ module GoogleSpreadsheets
16
16
 
17
17
  autoload :Enhanced
18
18
  autoload :LinkRelations
19
+ autoload :Auth
19
20
 
20
21
  class BaseError < StandardError
21
22
  DefaultMessage = nil
metadata CHANGED
@@ -1,64 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activeresource-google_spreadsheets
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.9
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Chihiro Ito
8
8
  - Toru KAWAMURA
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2014-09-22 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2014-11-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: activeresource
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- requirements:
20
- - &id002
21
- - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
24
21
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
27
29
  name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
28
36
  prerelease: false
29
- requirement: &id003 !ruby/object:Gem::Requirement
30
- requirements:
31
- - *id002
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: google-api-client
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
32
49
  type: :runtime
33
- version_requirements: *id003
34
- - !ruby/object:Gem::Dependency
35
- name: bundler
36
50
  prerelease: false
37
- requirement: &id004 !ruby/object:Gem::Requirement
38
- requirements:
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
39
60
  - - ~>
40
- - !ruby/object:Gem::Version
41
- version: "1.3"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
42
63
  type: :development
43
- version_requirements: *id004
44
- - !ruby/object:Gem::Dependency
45
- name: rake
46
64
  prerelease: false
47
- requirement: &id005 !ruby/object:Gem::Requirement
48
- requirements:
49
- - *id002
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
50
77
  type: :development
51
- version_requirements: *id005
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
52
84
  description: Google Spreadsheets accessor with ActiveResource
53
- email:
85
+ email:
54
86
  - tkawa@4bit.net
55
87
  executables: []
56
-
57
88
  extensions: []
58
-
59
89
  extra_rdoc_files: []
60
-
61
- files:
90
+ files:
62
91
  - .gitignore
63
92
  - Gemfile
64
93
  - LICENSE.txt
@@ -67,6 +96,8 @@ files:
67
96
  - activeresource-google_spreadsheets.gemspec
68
97
  - lib/activeresource-google_spreadsheets.rb
69
98
  - lib/google_spreadsheets.rb
99
+ - lib/google_spreadsheets/auth.rb
100
+ - lib/google_spreadsheets/auth/service_accounts_access_token.rb
70
101
  - lib/google_spreadsheets/base.rb
71
102
  - lib/google_spreadsheets/connection.rb
72
103
  - lib/google_spreadsheets/enhanced.rb
@@ -85,27 +116,27 @@ files:
85
116
  - lib/google_spreadsheets/version.rb
86
117
  - lib/google_spreadsheets/worksheet.rb
87
118
  homepage: https://github.com/tkawa/activeresource-google_spreadsheets
88
- licenses:
119
+ licenses:
89
120
  - MIT
90
121
  metadata: {}
91
-
92
122
  post_install_message:
93
123
  rdoc_options: []
94
-
95
- require_paths:
124
+ require_paths:
96
125
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
98
- requirements:
99
- - *id002
100
- required_rubygems_version: !ruby/object:Gem::Requirement
101
- requirements:
102
- - *id002
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
103
136
  requirements: []
104
-
105
137
  rubyforge_project:
106
- rubygems_version: 2.0.14
138
+ rubygems_version: 2.4.3
107
139
  signing_key:
108
140
  specification_version: 4
109
141
  summary: Google Spreadsheets accessor with ActiveResource
110
142
  test_files: []
111
-