localio 0.1.1 → 0.1.2

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
1
  ---
2
2
  SHA1:
3
- metadata.gz: 557ff500076f77cf2d3a1c650b62892d60e92b32
4
- data.tar.gz: 6d59d95e89c9d8d76cf66caebf6beb8ca5f925ca
3
+ metadata.gz: d642ee7edb710d0bc09402f50e601c6853d4f1d4
4
+ data.tar.gz: 242d3eccac6d02fab44194c4d541d33311fe4a41
5
5
  SHA512:
6
- metadata.gz: 1b2feb3cc3c969f72c3ba540c83f7b38ffd81dee6499737203febc72d4e9e1a2ad4718d92a9ad6fa3e046ba951a9af653d521bab9d05aea2aa6966fb9810aa33
7
- data.tar.gz: fb6bdeeb00d8586974bbebcf7a55cd809e30c9db623a11b4fe086de2a20f19817f1d9b6d54a5b6310e9ff26770fe074daa61209566c366b09ee09fac398de5da
6
+ metadata.gz: 8e4d633dd7957e90545d80afe7dd0d6fe8a02e5a0d06df30ee75148a097e0786dba303e6a8dab2600b8b7b1ed1af6732f29ff17382030086949c8b43df4cafe4
7
+ data.tar.gz: 976cfba61f9a1475f9b2cc647cf478908f5cbec5c5fe0fdae44b6df04db085a997865d82bdd0f09e94d7828e936aadb15024da7db147f56b9e50af768aa605fb
data/README.md CHANGED
@@ -113,7 +113,6 @@ Option | Description
113
113
  `:password` | **DEPRECATED** This is deprecated starting version 0.1.0. Please remove it.
114
114
  `:client_id` | (Req.) Your Google CLIENT ID.
115
115
  `:client_secret` | (Req.) Your Google CLIENT SECRET.
116
- `:access_token` | Your generated access token. You will get it the first time you log in and give permissions to your generated Google Developer Console application.
117
116
 
118
117
  Please take into account that from version 0.1.0 of Localio onwards we are using **Google OAuth2 authentication**, as the previous one with login/password has been deprecated by Google and cannot be access anymore starting April 20th 2015.
119
118
 
@@ -137,19 +136,9 @@ source :google_drive,
137
136
 
138
137
  Then, the first time you run it, you will be prompted to follow some instructions. You will be asked to open a website, where you will be prompted for permission to use the Drive API. After you allow it, you will be given an authorization code, which you will have to paste in your terminal screen when prompted.
139
138
 
140
- After all this is done, you will be given in the `:access_token` in the output. Just add it to the `source` parameters, as you did with the id and secret before, and that's it. It will look now like this:
139
+ **NOTE** A hidden file, called .localio.yml, will be created in your Locfile directory. You should **add that file to your ignored resources** in your repository, aka the **.gitignore** file.
141
140
 
142
- ```ruby
143
- source :google_drive,
144
- :spreadsheet => '[Localizables] My Project',
145
- :client_id => 'XXXXXXXXX-XXXXXXXX.apps.googleusercontent.com',
146
- :client_secret => 'asdFFGGhjKlzxcvbnm',
147
- :access_token => 'ya29.RAEXXxxxxsadsadajsdhasuidhakjsdhkajhsduiahsduiasd89a8912'
148
- ```
149
-
150
- When the Locfile contains the `:access_token`, all the login in process for generating localizables will be automatic and won't require your attention. The parameters for `:client_id` and `:client_secret` are not really needed anymore, although you could leave them there if you want.
151
-
152
- **NOTE** As it is a very bad practice to put your sensitive information in a plain file, specially when you would want to upload your project to some repository, it is **VERY RECOMMENDED** that you use environment variables in here. Ruby syntax is accepted so you can use `ENV['CLIENT_SECRET']`, `ENV['CLIENT_ID']` and `ENV['ACCESS_TOKEN']` in here.
141
+ **NOTE** As it is a very bad practice to put your sensitive information in a plain file, specially when you would want to upload your project to some repository, it is **VERY RECOMMENDED** that you use environment variables in here. Ruby syntax is accepted so you can use `ENV['CLIENT_SECRET']` and `ENV['CLIENT_ID']` in here.
153
142
 
154
143
  For example, this.
155
144
 
@@ -157,8 +146,7 @@ For example, this.
157
146
  source :google_drive,
158
147
  :spreadsheet => '[Localizables] My Project!',
159
148
  :client_id => ENV['CLIENT_ID'],
160
- :client_secret => ENV['CLIENT_SECRET'],
161
- :access_token => ENV['ACCESS_TOKEN']
149
+ :client_secret => ENV['CLIENT_SECRET']
162
150
  ````
163
151
 
164
152
  And in your .bashrc (or .bash_profile, .zshrc or whatever), you could export those environment variables like this:
@@ -166,7 +154,6 @@ And in your .bashrc (or .bash_profile, .zshrc or whatever), you could export tho
166
154
  ````ruby
167
155
  export CLIENT_ID="your_client_id"
168
156
  export CLIENT_SECRET="your_client_secret"
169
- export ACCESS_TOKEN="your_access_token"
170
157
  ````
171
158
 
172
159
  ##### XLS
@@ -0,0 +1,37 @@
1
+ class ConfigStore
2
+ CONFIG_FILE = '.localio.yml'
3
+
4
+ def initialize
5
+ if File.exist? CONFIG_FILE
6
+ @config = YAML.load_file(CONFIG_FILE)
7
+ end
8
+ @config ||= Hash.new
9
+ end
10
+
11
+ def has?(key)
12
+ @config.has_key?(clean_param key)
13
+ end
14
+
15
+ def get(key)
16
+ @config[clean_param key]
17
+ end
18
+
19
+ def store(key, data)
20
+ @config[clean_param key] = data
21
+ end
22
+
23
+ def persist
24
+ File.open(CONFIG_FILE, 'w') do |h|
25
+ h.write @config.to_yaml
26
+ end
27
+ end
28
+
29
+ private
30
+ def clean_param(param)
31
+ if param.is_a?(Symbol)
32
+ param.to_s
33
+ else
34
+ param
35
+ end
36
+ end
37
+ end
@@ -1,10 +1,10 @@
1
1
  require 'google_drive'
2
2
  require 'localio/term'
3
+ require 'localio/config_store'
3
4
 
4
5
  class GoogleDriveProcessor
5
6
 
6
7
  def self.load_localizables(platform_options, options)
7
-
8
8
  # Parameter validations
9
9
  spreadsheet = options[:spreadsheet]
10
10
  raise ArgumentError, ':spreadsheet required for Google Drive source!' if spreadsheet.nil?
@@ -18,13 +18,10 @@ class GoogleDriveProcessor
18
18
  # New authentication way
19
19
  client_id = options[:client_id]
20
20
  client_secret = options[:client_secret]
21
- access_token = options[:access_token]
22
21
 
23
- # We need client_id / client_secret if we dont have an access token
24
- if access_token.nil?
25
- raise ArgumentError, ':client_id required for Google Drive. Check how to get it here: https://developers.google.com/drive/web/auth/web-server' if client_id.nil?
26
- raise ArgumentError, ':client_secret required for Google Drive. Check how to get it here: https://developers.google.com/drive/web/auth/web-server' if client_secret.nil?
27
- end
22
+ # We need client_id / client_secret
23
+ raise ArgumentError, ':client_id required for Google Drive. Check how to get it here: https://developers.google.com/drive/web/auth/web-server' if client_id.nil?
24
+ raise ArgumentError, ':client_secret required for Google Drive. Check how to get it here: https://developers.google.com/drive/web/auth/web-server' if client_secret.nil?
28
25
 
29
26
  override_default = nil
30
27
  override_default = platform_options[:override_default] unless platform_options.nil? or platform_options[:override_default].nil?
@@ -32,25 +29,37 @@ class GoogleDriveProcessor
32
29
  # Log in and get spreadsheet
33
30
  puts 'Logging in to Google Drive...'
34
31
  begin
35
- if access_token.nil?
36
- puts "No :access_token found. Let\'s proceed to get one!".red
37
- client = Google::APIClient.new application_name: 'Localio', application_version: Localio::VERSION
38
- auth = client.authorization
39
- auth.client_id = client_id
40
- auth.client_secret = client_secret
41
- auth.scope =
42
- "https://www.googleapis.com/auth/drive " +
43
- "https://spreadsheets.google.com/feeds/"
44
- auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
32
+ client = Google::APIClient.new application_name: 'Localio', application_version: Localio::VERSION
33
+ auth = client.authorization
34
+ auth.client_id = client_id
35
+ auth.client_secret = client_secret
36
+ auth.scope =
37
+ "https://docs.google.com/feeds/" +
38
+ "https://www.googleapis.com/auth/drive " +
39
+ "https://spreadsheets.google.com/feeds/"
40
+ auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
41
+
42
+ config = ConfigStore.new
43
+
44
+ access_token = nil
45
+
46
+ if config.has? :refresh_token
47
+ puts 'Refreshing auth token...'
48
+ auth.refresh_token = config.get :refresh_token
49
+ auth.refresh!
50
+ access_token = auth.access_token
51
+ else
45
52
  puts "1. Open this page in your browser:\n#{auth.authorization_uri}\n\n"
46
53
  puts "2. Enter the authorization code shown in the page: "
47
54
  auth.code = $stdin.gets.chomp
48
55
  auth.fetch_access_token!
49
56
  access_token = auth.access_token
50
- puts '\n**IMPORTANT** You can store your access_token in the Locfile :source parameter for avoiding this step in the future:\n'
51
- puts ":access_token => '#{access_token}'".yellow
52
- puts '\n\n'
53
57
  end
58
+
59
+ config.store :refresh_token, auth.refresh_token
60
+ config.store :access_token, auth.access_token
61
+ config.persist
62
+
54
63
  # Creates a session
55
64
  session = GoogleDrive.login_with_oauth(access_token)
56
65
  rescue => e
@@ -70,7 +79,7 @@ class GoogleDriveProcessor
70
79
  when 0
71
80
  abort "Unable to find any spreadsheet matching your criteria: #{spreadsheet}"
72
81
  else
73
- abort 'More than one match found. You have to be more specific!'
82
+ abort "More than one match found (#{matching_spreadsheets.join ', '}). You have to be more specific!"
74
83
  end
75
84
 
76
85
 
@@ -1,3 +1,3 @@
1
1
  module Localio
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/localio.gemspec CHANGED
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'localio/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "localio"
8
- spec.version = Localio::VERSION
9
- spec.authors = ["Nacho Lopez"]
10
- spec.email = ["nacho@nlopez.io"]
11
- spec.description = %q{Automatic Localizable file generation for multiple platforms (Rails YAML, Android, Java Properties, iOS, JSON, .NET ResX)}
12
- spec.summary = %q{Automatic Localizable file generation for multiple type of files, like Android string.xml, Xcode Localizable.strings, JSON files, Rails YAML files, Java properties, etc. reading from Google Drive and Excel spreadsheets as base.}
13
- spec.homepage = "http://github.com/mrmans0n/localio"
14
- spec.license = "MIT"
7
+ spec.name = "localio"
8
+ spec.version = Localio::VERSION
9
+ spec.authors = ["Nacho Lopez"]
10
+ spec.email = ["nacho@nlopez.io"]
11
+ spec.description = %q{Automatic Localizable file generation for multiple platforms (Rails YAML, Android, Java Properties, iOS, JSON, .NET ResX)}
12
+ spec.summary = %q{Automatic Localizable file generation for multiple type of files, like Android string.xml, Xcode Localizable.strings, JSON files, Rails YAML files, Java properties, etc. reading from Google Drive and Excel spreadsheets as base.}
13
+ spec.homepage = "http://github.com/mrmans0n/localio"
14
+ spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
-
20
+
21
21
  spec.executables << "localize"
22
22
 
23
23
  spec.add_development_dependency "rspec"
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
28
28
  spec.add_development_dependency "rake"
29
-
29
+
30
30
  spec.add_dependency "micro-optparse", "~> 1.2"
31
31
  spec.add_dependency "google_drive", "1.0.0"
32
32
  spec.add_dependency "spreadsheet", "~> 1.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nacho Lopez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -139,6 +139,7 @@ files:
139
139
  - Rakefile
140
140
  - bin/localize
141
141
  - lib/localio.rb
142
+ - lib/localio/config_store.rb
142
143
  - lib/localio/filter.rb
143
144
  - lib/localio/formatter.rb
144
145
  - lib/localio/localizable_writer.rb