pry-parsecom 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +1 -0
- data/bin/pry-parsecom +13 -0
- data/lib/pry-parsecom/commands/login_parsecom.rb +19 -0
- data/lib/pry-parsecom/commands/logout_parsecom.rb +19 -0
- data/lib/pry-parsecom/commands/show_applications.rb +23 -0
- data/lib/pry-parsecom/commands/show_classes.rb +34 -0
- data/lib/pry-parsecom/commands/show_credentials.rb +24 -0
- data/lib/pry-parsecom/commands/show_schema.rb +39 -0
- data/lib/pry-parsecom/commands/use_application.rb +37 -0
- data/lib/pry-parsecom/commands.rb +11 -0
- data/lib/pry-parsecom/model_formatter.rb +7 -0
- data/lib/pry-parsecom/setting.rb +210 -0
- data/lib/pry-parsecom/table.rb +57 -0
- data/lib/pry-parsecom/version.rb +5 -0
- data/lib/pry-parsecom.rb +27 -0
- data/pry-parsecom.gemspec +24 -0
- data/todo.txt +6 -0
- metadata +116 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ando Yasushi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# pry-parsecom
|
2
|
+
|
3
|
+
CLI for parse.com
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
$ pry-parsecom
|
8
|
+
[1] pry(main)> help parse.com
|
9
|
+
Parse.com
|
10
|
+
login-parsecom Log in parse.com
|
11
|
+
logout-parsecom Log out parse.com
|
12
|
+
show-applications Show all parse applications
|
13
|
+
show-classes Show all parse classes
|
14
|
+
show-credentials Show credentials for parse.com
|
15
|
+
show-schema Show a parse class schema
|
16
|
+
use-application Set the current parse.com application
|
17
|
+
[2] pry(main)> show-applications
|
18
|
+
Input parse.com email: andyjpn@gmail.com
|
19
|
+
Input parse.com password:
|
20
|
+
Name | Selected
|
21
|
+
===================
|
22
|
+
FakeApp |
|
23
|
+
FakeApp2 |
|
24
|
+
[3] pry(main)> use-application FakeApp
|
25
|
+
The current app is FakeApp.
|
26
|
+
[4] pry(main)> show-applications
|
27
|
+
Name | Selected
|
28
|
+
===================
|
29
|
+
FakeApp | *
|
30
|
+
FakeApp2 |
|
31
|
+
[5] pry(main)> show-credentials
|
32
|
+
Key | Value
|
33
|
+
=========================================================
|
34
|
+
APPLICATION_ID | abcdefghijklmnopqrstuvwxyzabcdefghijklmn
|
35
|
+
REST_API_KEY | abcdefghijklmnopqrstuvwxyzabcdefghijklmn
|
36
|
+
MASTER_KEY | abcdefghij******************************
|
37
|
+
[6] pry(main)> show-classes
|
38
|
+
Name
|
39
|
+
=======
|
40
|
+
Comment
|
41
|
+
Post
|
42
|
+
_User
|
43
|
+
[7] pry(main)> show-schema Post
|
44
|
+
Name | Type
|
45
|
+
============================
|
46
|
+
author | pointer<_User>
|
47
|
+
body | string
|
48
|
+
comments | relation<Comment>
|
49
|
+
[8] pry(main)> Post.find :all
|
50
|
+
=> [---
|
51
|
+
__type: Post
|
52
|
+
author:
|
53
|
+
__type: Pointer
|
54
|
+
className: _User
|
55
|
+
objectId: ZybBXQEIjI
|
56
|
+
body: 本文
|
57
|
+
comments: <Ralations>
|
58
|
+
createdAt: '2013-11-17T13:37:44.055Z'
|
59
|
+
updatedAt: '2013-11-17T13:38:30.908Z'
|
60
|
+
objectId: lNKMPYSCTw
|
61
|
+
,
|
62
|
+
---
|
63
|
+
__type: Post
|
64
|
+
author:
|
65
|
+
__type: Pointer
|
66
|
+
className: _User
|
67
|
+
objectId: ZybBXQEIjI
|
68
|
+
body: 本文2
|
69
|
+
comments: <Ralations>
|
70
|
+
createdAt: '2013-11-17T14:33:00.134Z'
|
71
|
+
updatedAt: '2013-11-17T14:33:25.436Z'
|
72
|
+
objectId: ur2StDqAFD
|
73
|
+
]
|
74
|
+
[9] pry(main)> logout
|
75
|
+
logged out
|
76
|
+
[10] pry(main)> show-applications
|
77
|
+
Name | Selected
|
78
|
+
===================
|
79
|
+
[11] pry(main)> exit
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/pry-parsecom
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command "login-parsecom" do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Log in parse.com'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner <<-EOS.gsub(/^\s+/, '')
|
9
|
+
Usage: login-parsecom
|
10
|
+
|
11
|
+
Log in parse.com
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
PryParsecom::Setting.login *PryParsecom.ask_email_and_password
|
17
|
+
output.puts 'logged in'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command "logout-parsecom" do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Log out parse.com'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner <<-EOS.gsub(/^\s+/, '')
|
9
|
+
Usage: logout-parsecom
|
10
|
+
|
11
|
+
Log in parse.com
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
PryParsecom::Setting.logout
|
17
|
+
output.puts 'logged out'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command "show-applications" do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Show all parse applications'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner unindent <<-EOS
|
9
|
+
Usage: show-applications
|
10
|
+
|
11
|
+
Show all parse applications
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
PryParsecom::Setting.setup_if_needed
|
17
|
+
table = PryParsecom::Table.new %w(Name Selected)
|
18
|
+
PryParsecom::Setting.app_names.each do |name|
|
19
|
+
table.add_row [name, name == PryParsecom::Setting.current_app ? '*' : '']
|
20
|
+
end
|
21
|
+
output.puts table
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command 'show-classes' do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Show all parse classes'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner unindent <<-EOS
|
9
|
+
Usage: show-classes [app_name]
|
10
|
+
|
11
|
+
Show all parse classes
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
if 1 < args.size
|
17
|
+
output.puts opt
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
PryParsecom::Setting.setup_if_needed
|
22
|
+
setting = PryParsecom::Setting.current_setting
|
23
|
+
unless setting
|
24
|
+
output.puts 'Now using no app'
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
table = PryParsecom::Table.new %w(Name)
|
29
|
+
setting.classes.each do |klass|
|
30
|
+
table.add_row klass
|
31
|
+
end
|
32
|
+
output.puts table
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command "show-credentials" do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Show credentials for parse.com'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner unindent <<-EOS
|
9
|
+
Usage: show-credentials
|
10
|
+
|
11
|
+
Show parse.com credentials: application_id, rest_api_key and master_key.
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
PryParsecom::Setting.setup_if_needed
|
17
|
+
table = PryParsecom::Table.new %w(Key Value), [
|
18
|
+
['APPLICATION_ID', Parse.application_id],
|
19
|
+
['REST_API_KEY', Parse.api_key],
|
20
|
+
['MASTER_KEY', (Parse.master_key || '').sub(/.{30}$/, '*' * 30)]
|
21
|
+
]
|
22
|
+
output.puts table
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command "show-schema" do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Show a parse class schema'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner unindent <<-EOS
|
9
|
+
Usage: show-schema [class name]
|
10
|
+
|
11
|
+
Show a parse class schema
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
unless args.size == 1
|
17
|
+
output.puts opt
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
PryParsecom::Setting.setup_if_needed
|
22
|
+
setting = PryParsecom::Setting.current_setting
|
23
|
+
unless setting
|
24
|
+
output.puts 'Now using no app'
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
class_name = args.first.to_s
|
29
|
+
schema = setting.schema class_name
|
30
|
+
table = PryParsecom::Table.new %w(Name Type)
|
31
|
+
schema.to_a.sort{|a1, a2| a1[0] <=> a2[0]}.each do |name, type|
|
32
|
+
if type =~ /^\*(.*)/
|
33
|
+
type = "pointer<#{$1}>"
|
34
|
+
end
|
35
|
+
table.add_row [name, type]
|
36
|
+
end
|
37
|
+
output.puts table
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
PryParsecom::Commands.create_command 'use-application' do
|
4
|
+
group 'Parse.com'
|
5
|
+
description 'Set the current parse.com application'
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.banner <<-EOS.gsub(/^\s+/, '')
|
9
|
+
Usage: use your-app-name
|
10
|
+
|
11
|
+
Set the current parse.com application
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def process
|
16
|
+
PryParsecom::Setting.setup_if_needed
|
17
|
+
unless args.size == 1
|
18
|
+
output.puts opt
|
19
|
+
return
|
20
|
+
end
|
21
|
+
app_name = args.first.to_s
|
22
|
+
unless PryParsecom::Setting.has_app? app_name
|
23
|
+
output.puts "#{app_name} does not exist."
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
unless PryParsecom::Setting.current_app.to_s.empty?
|
28
|
+
prev_setting = PryParsecom::Setting.current_setting
|
29
|
+
prev_setting.reset if prev_setting
|
30
|
+
end
|
31
|
+
|
32
|
+
setting = PryParsecom::Setting[app_name]
|
33
|
+
setting.set
|
34
|
+
PryParsecom::Setting.current_app = app_name
|
35
|
+
output.puts "The current app is #{app_name}."
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
module PryParsecom
|
2
|
+
class Setting
|
3
|
+
DOT_DIRNAME = "#{Dir.home}/.pry-parsecom"
|
4
|
+
SETTINGS_FILENAME = "settings"
|
5
|
+
IGNORES_FILENAME = "ignores"
|
6
|
+
KEYS_FILENAME = "keys"
|
7
|
+
SCHEMAS_FILENAME = "schemas"
|
8
|
+
|
9
|
+
USER_AGENT = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
|
10
|
+
LOGIN_URL = 'https://parse.com/apps'
|
11
|
+
LOGIN_SUCCESS_FILENAME= 'apps.html'
|
12
|
+
LOGIN_ERROR_FILENAME = 'user_session.html'
|
13
|
+
APPS_XPATH = '/html/body/div[4]/div[2]/div/div/div/div[3]/ul/li/ul/li/a'
|
14
|
+
APP_NAME_XPATH = '//*[@id="parse_app_name"]'
|
15
|
+
APP_KEYS_CSS = 'div.app_keys.window'
|
16
|
+
APP_ID_XPATH = 'div[2]/div[1]/div[2]/div/input'
|
17
|
+
API_KEY_XPATH = 'div[2]/div[5]/div[2]/div/input'
|
18
|
+
MASTER_KEY_XPATH = 'div[2]/div[6]/div[2]/div/input'
|
19
|
+
|
20
|
+
@@agent = Mechanize.new
|
21
|
+
@@agent.user_agent = USER_AGENT
|
22
|
+
@@current_app = nil
|
23
|
+
@@apps = {}
|
24
|
+
|
25
|
+
class <<self
|
26
|
+
def current_app
|
27
|
+
@@current_app
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_app= app
|
31
|
+
@@current_app = app
|
32
|
+
end
|
33
|
+
|
34
|
+
def current_setting
|
35
|
+
@@apps[@@current_app]
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_if_needed
|
39
|
+
if @@apps.empty?
|
40
|
+
unless load
|
41
|
+
login *PryParsecom.ask_email_and_password
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def read_setting_file name
|
47
|
+
begin File.read "#{DOT_DIRNAME}/#{name}" rescue '' end
|
48
|
+
end
|
49
|
+
|
50
|
+
def write_setting_file name, hash
|
51
|
+
Dir.mkdir DOT_DIRNAME unless File.exist? DOT_DIRNAME
|
52
|
+
File.open "#{DOT_DIRNAME}/#{name}", 'w' do |file|
|
53
|
+
file.write YAML.dump(hash)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def load
|
58
|
+
if File.exist? DOT_DIRNAME
|
59
|
+
settings = read_setting_file SETTINGS_FILENAME
|
60
|
+
ignores = read_setting_file IGNORES_FILENAME
|
61
|
+
keys = read_setting_file KEYS_FILENAME
|
62
|
+
schemas = read_setting_file SCHEMAS_FILENAME
|
63
|
+
|
64
|
+
if !keys.empty? && !schemas.empty?
|
65
|
+
ignores = ignores.split "\n"
|
66
|
+
keys = YAML.load keys
|
67
|
+
schemas = YAML.load schemas
|
68
|
+
keys.each do |app_name, key|
|
69
|
+
@@apps[app_name] = Setting.new app_name, key['app_id'], key['api_key'],
|
70
|
+
key['master_key'], schemas[app_name]
|
71
|
+
end
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
def save
|
79
|
+
keys = {}
|
80
|
+
schemas = {}
|
81
|
+
@@apps.each do |app_name, setting|
|
82
|
+
keys[app_name] = {
|
83
|
+
'app_id' => setting.app_id,
|
84
|
+
'api_key' => setting.api_key,
|
85
|
+
'master_key' => setting.master_key
|
86
|
+
}
|
87
|
+
|
88
|
+
schemas[app_name] = setting.schemas
|
89
|
+
end
|
90
|
+
write_setting_file KEYS_FILENAME, keys
|
91
|
+
write_setting_file SCHEMAS_FILENAME, schemas
|
92
|
+
end
|
93
|
+
|
94
|
+
def login email, password
|
95
|
+
@@apps = {}
|
96
|
+
|
97
|
+
login_page = @@agent.get LOGIN_URL
|
98
|
+
apps_page = login_page.form_with :id => 'new_user_session' do |form|
|
99
|
+
form['user_session[email]'] = email
|
100
|
+
form['user_session[password]'] = password
|
101
|
+
end.submit
|
102
|
+
|
103
|
+
if apps_page.filename == LOGIN_ERROR_FILENAME
|
104
|
+
puts 'login error'
|
105
|
+
return
|
106
|
+
end
|
107
|
+
|
108
|
+
apps_page.search(APPS_XPATH).each do |a|
|
109
|
+
href = a.attributes['href'].to_s
|
110
|
+
count_page = @@agent.get "#{href}/collections/count"
|
111
|
+
schema = JSON.parse count_page.content
|
112
|
+
edit_page = @@agent.get "#{href}/edit"
|
113
|
+
app_name = edit_page.search(APP_NAME_XPATH).first.attributes['value'].to_s
|
114
|
+
app_keys = edit_page.search('div.app_keys.window')
|
115
|
+
app_id = app_keys.search(APP_ID_XPATH).first.attributes['value'].to_s
|
116
|
+
api_key = app_keys.search(API_KEY_XPATH).first.attributes['value'].to_s
|
117
|
+
master_key = app_keys.search(MASTER_KEY_XPATH).first.attributes['value'].to_s
|
118
|
+
|
119
|
+
next if read_setting_file(IGNORES_FILENAME).split("\n").include? app_name
|
120
|
+
|
121
|
+
@@apps[app_name] = Setting.new app_name, app_id, api_key, master_key, schema
|
122
|
+
end
|
123
|
+
|
124
|
+
save
|
125
|
+
end
|
126
|
+
|
127
|
+
def logout
|
128
|
+
FileUtils.rm "#{DOT_DIRNAME}/#{KEYS_FILENAME}"
|
129
|
+
FileUtils.rm "#{DOT_DIRNAME}/#{SCHEMAS_FILENAME}"
|
130
|
+
@@apps.clear
|
131
|
+
@@current_app = nil
|
132
|
+
end
|
133
|
+
|
134
|
+
def app_names
|
135
|
+
@@apps.keys
|
136
|
+
end
|
137
|
+
|
138
|
+
def has_app? app_name
|
139
|
+
@@apps.has_key? app_name.to_s
|
140
|
+
end
|
141
|
+
|
142
|
+
def by_name app_name
|
143
|
+
@@apps[app_name.to_s]
|
144
|
+
end
|
145
|
+
alias [] by_name
|
146
|
+
|
147
|
+
def each &block
|
148
|
+
@@apps.each &block
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
attr_accessor :app_name, :app_id, :api_key, :master_key, :schemas
|
153
|
+
|
154
|
+
def initialize app_name, app_id, api_key, master_key, schemas
|
155
|
+
@app_name, @app_id, @api_key, @master_key, @schemas =
|
156
|
+
app_name, app_id, api_key, master_key, schemas
|
157
|
+
end
|
158
|
+
|
159
|
+
def set
|
160
|
+
Parse.credentials :application_id => @app_id, :api_key => @api_key, :master_key => @master_key
|
161
|
+
Parse::Client.default.application_id = @app_id
|
162
|
+
Parse::Client.default.api_key = @api_key
|
163
|
+
Parse::Client.default.master_key = @master_key
|
164
|
+
|
165
|
+
schemas['collection'].each do |e|
|
166
|
+
class_name = e['id']
|
167
|
+
next if class_name[0] == '_'
|
168
|
+
|
169
|
+
if Object.const_defined? class_name
|
170
|
+
puts "#{class_name.to_s} has already exist."
|
171
|
+
next
|
172
|
+
end
|
173
|
+
Parse::Object class_name
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def reset
|
178
|
+
schemas['collection'].each do |e|
|
179
|
+
class_name = e['id']
|
180
|
+
next if class_name[0] == '_'
|
181
|
+
|
182
|
+
if Object.const_defined? class_name
|
183
|
+
klass = Object.const_get class_name
|
184
|
+
if klass < Parse::Object
|
185
|
+
Object.class_eval do
|
186
|
+
remove_const class_name
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
Parse.credentials :application_id => '', :api_key => '', :mater_key => ''
|
193
|
+
Parse::Client.default.application_id = nil
|
194
|
+
Parse::Client.default.api_key = nil
|
195
|
+
Parse::Client.default.master_key = nil
|
196
|
+
Parse::Client.default
|
197
|
+
end
|
198
|
+
|
199
|
+
def classes
|
200
|
+
schemas['collection'].map{|e| e['id']}.sort
|
201
|
+
end
|
202
|
+
|
203
|
+
def schema class_name
|
204
|
+
schms = schemas['collection'].select do |e|
|
205
|
+
e['id'] == class_name || e['display_name'] == class_name
|
206
|
+
end
|
207
|
+
schms.empty? ? [] : schms.first['schema']
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module PryParsecom
|
2
|
+
class Table
|
3
|
+
def initialize heads, rows=[]
|
4
|
+
@heads = heads
|
5
|
+
@col_widths = Hash.new 0
|
6
|
+
@heads.each do |head|
|
7
|
+
@col_widths[head] = head.size
|
8
|
+
end
|
9
|
+
self.rows = rows
|
10
|
+
end
|
11
|
+
|
12
|
+
def rows= rows
|
13
|
+
@rows = []
|
14
|
+
rows.each do |row|
|
15
|
+
add_row row
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_row row
|
20
|
+
cols = []
|
21
|
+
case row
|
22
|
+
when Hash
|
23
|
+
@heads.each do |head|
|
24
|
+
cols << row[head]
|
25
|
+
end
|
26
|
+
when Array
|
27
|
+
cols = row
|
28
|
+
else
|
29
|
+
cols = [row]
|
30
|
+
end
|
31
|
+
|
32
|
+
cols.each.with_index do |col, i|
|
33
|
+
if @col_widths[i] < col.size
|
34
|
+
@col_widths[i] = col.size
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@rows << cols
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
heads = @heads.map.with_index do |head, i|
|
42
|
+
head.center @col_widths[i]
|
43
|
+
end.join " | "
|
44
|
+
ret = heads
|
45
|
+
ret += "\n"
|
46
|
+
ret += '=' * heads.size
|
47
|
+
ret += "\n"
|
48
|
+
@rows.each do |row|
|
49
|
+
ret += row.map.with_index { |col, i|
|
50
|
+
col.ljust @col_widths[i]
|
51
|
+
}.join " | "
|
52
|
+
ret += "\n"
|
53
|
+
end
|
54
|
+
ret
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/pry-parsecom.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'pry-parsecom/version'
|
3
|
+
|
4
|
+
if ENV['ENABLE_PRY_PARSECOM']
|
5
|
+
require 'io/console'
|
6
|
+
require 'parsecom'
|
7
|
+
require 'mechanize'
|
8
|
+
require 'json'
|
9
|
+
require 'yaml'
|
10
|
+
require 'pry-parsecom/setting'
|
11
|
+
require 'pry-parsecom/commands'
|
12
|
+
require 'pry-parsecom/table'
|
13
|
+
require 'pry-parsecom/model_formatter'
|
14
|
+
|
15
|
+
module PryParsecom
|
16
|
+
module_function
|
17
|
+
|
18
|
+
def ask_email_and_password
|
19
|
+
print 'Input parse.com email: '
|
20
|
+
email = gets
|
21
|
+
print 'Input parse.com password: '
|
22
|
+
password = STDIN.noecho(&:gets)
|
23
|
+
puts
|
24
|
+
[email.strip, password.strip]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pry-parsecom/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "pry-parsecom"
|
8
|
+
gem.version = PryParsecom::VERSION
|
9
|
+
gem.authors = ["Ando Yasushi"]
|
10
|
+
gem.email = ["andyjpn@gmail.com"]
|
11
|
+
gem.description = %q{CLI for parse.com}
|
12
|
+
gem.summary = %q{CLI for parse.com}
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency "pry"
|
22
|
+
gem.add_dependency "parsecom"
|
23
|
+
gem.add_dependency "mechanize"
|
24
|
+
end
|
data/todo.txt
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-parsecom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ando Yasushi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pry
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: parsecom
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mechanize
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: CLI for parse.com
|
63
|
+
email:
|
64
|
+
- andyjpn@gmail.com
|
65
|
+
executables:
|
66
|
+
- pry-parsecom
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/pry-parsecom
|
76
|
+
- lib/pry-parsecom.rb
|
77
|
+
- lib/pry-parsecom/commands.rb
|
78
|
+
- lib/pry-parsecom/commands/login_parsecom.rb
|
79
|
+
- lib/pry-parsecom/commands/logout_parsecom.rb
|
80
|
+
- lib/pry-parsecom/commands/show_applications.rb
|
81
|
+
- lib/pry-parsecom/commands/show_classes.rb
|
82
|
+
- lib/pry-parsecom/commands/show_credentials.rb
|
83
|
+
- lib/pry-parsecom/commands/show_schema.rb
|
84
|
+
- lib/pry-parsecom/commands/use_application.rb
|
85
|
+
- lib/pry-parsecom/model_formatter.rb
|
86
|
+
- lib/pry-parsecom/setting.rb
|
87
|
+
- lib/pry-parsecom/table.rb
|
88
|
+
- lib/pry-parsecom/version.rb
|
89
|
+
- pry-parsecom.gemspec
|
90
|
+
- todo.txt
|
91
|
+
homepage: ''
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.8.23
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: CLI for parse.com
|
116
|
+
test_files: []
|