leif 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14358331d926739fcb9ddaf54f07ce82cec9dc0e
4
- data.tar.gz: b3f7f28d1530a0c7b3ea479fad8fb9a221b861d0
3
+ metadata.gz: 9d21327777d65dd1e53077d2ee7f800dac2c93a6
4
+ data.tar.gz: ed6d1bf362b4eaa69bc2ddcc416f9164e7d5022d
5
5
  SHA512:
6
- metadata.gz: e32dd3fef31bf00c8857688e647510e625ce6f77b5875fd1307ae9d10124ae4613985a98566be1ae6c2eb89d203fc50f236544f381dc34c0da8605d517eb841f
7
- data.tar.gz: dd73d4a03a69ab51abed53c039e2dcc68af1b196f2f584525b693b02fdc21b2057d51d3e1c0003684be4ce2d0030598f31d1912533f9c14728cdef4e26e0e641
6
+ metadata.gz: 2f8e3aa4056db2da381cb4cad711ed3cc63868457b0cfc3fec1bdc93b98f730632d1a305d1d2868bdb21a769486e9d35c9ec9e1f5b12cfbe485283ec2e6393fc
7
+ data.tar.gz: 04cb8df37f9aa1cf0410ad4695fde9b601cbb841a4e7574cc639338eab634b2849fac3df64bf616fa5002a67030f3857dee7fcdb2e9ead4f5a4d1a66df3159cd
data/README.md CHANGED
@@ -22,6 +22,8 @@ $ gem install gem-man
22
22
  $ gem man leif
23
23
  ```
24
24
 
25
+ [manpage]: http://cloudapp.github.io/leif
26
+
25
27
  ## Interactive Commands
26
28
 
27
29
  - `root`:
@@ -79,35 +81,69 @@ $ gem man leif
79
81
  The UI is weak at this point and not very intuitive. To get started, here's a
80
82
  sample workflow. It should give you a general overview of what's possible.
81
83
 
84
+ $ leif
85
+ ...
86
+
87
+ -- Links --
88
+ account, authorization
89
+
82
90
  > follow authorization
91
+ ...
83
92
 
84
93
  > basic arthur@dent.com
85
94
  Password: *****
95
+ ...
96
+ {
97
+ "name": "token",
98
+ "value": "2c2p2B2Y0U3y3c2c"
99
+ },
100
+ ...
86
101
 
87
- > token <token copied from response body>
102
+ > token 2c2p2B2Y0U3y3c2c
103
+ ...
104
+
105
+ -- Links --
106
+ drops, drops-template, stream, store
88
107
 
89
108
  > follow drops
90
- > follow next
91
- > follow first
109
+ ...
92
110
 
93
111
  > create
112
+ ...
113
+ Fill the template to create a new item.
114
+ name [null]: New Drop
115
+ private [null]: false
116
+ trash [false]:
117
+ bookmark_url [null]: http://getcloudapp.com
118
+ file_size [null]:
119
+ ...
120
+
121
+ > items
122
+ ...
123
+ Select this item [y,n]? y
124
+
125
+ -- Links --
126
+ collection, canonical, icon
127
+
128
+ > follow collection
129
+ ...
130
+
131
+ > items
132
+ ...
133
+ Select this item [y,n]? y
134
+ ...
94
135
 
95
- Name (empty to submit): name
96
- Value: CloudApp
97
-
98
- Name (empty to submit): bookmark_url
99
- Value: http://getcloudapp.com
100
-
101
- Name (empty to submit):
102
-
103
- > root
104
- > follow drops
105
136
  > update
137
+ ...
138
+ Fill the template to update the item.
139
+ name ["New Drop"]: Updated Drop
140
+ private [false]:
141
+ trash [false]:
142
+ bookmark_url [null]:
143
+ file_size [null]:
144
+ ...
106
145
 
107
- Name (empty to submit): name
108
- Value: The Guide
109
-
110
- Name (empty to submit):
111
-
112
-
113
- [manpage]: http://cloudapp.github.io/leif
146
+ > root
147
+ ...
148
+ -- Links --
149
+ drops, drops-template, account, stream
data/lib/leif/cli.rb CHANGED
@@ -76,38 +76,29 @@ module Leif
76
76
  make_request subject.link_href(relation)
77
77
  end
78
78
 
79
- def create_item
80
- template = collection.template
81
-
82
- loop do
83
- print_template template, 'Create Item'
84
- puts
85
- puts 'Fill the template to create a new item.'
86
- name = ask('Name (empty to submit): ')
87
- break if name.empty?
88
- value = ask_for_primitive('Value: ')
89
-
90
- template = template.fill_field name, value
79
+ def fill_and_submit_template(template, label)
80
+ print_template template
81
+ puts
82
+ puts label
83
+ template.each do |name, value|
84
+ printed_value = value.inspect
85
+ printed_value = 'null' if printed_value == 'nil'
86
+ new_value = ask("#{name} [#{printed_value}]: ")
87
+ new_value = new_value.empty? ? value : convert_to_primitive(new_value)
88
+ template = template.fill_field name, new_value
91
89
  end
92
90
 
93
91
  make_request template.href, template.convert_to_json, template.method
94
92
  end
95
93
 
96
- def update(item)
97
- template = collection.item_template item
98
-
99
- loop do
100
- print_template template, 'Update Item'
101
- puts
102
- puts 'Fill the template to update the item.'
103
- name = ask('Name (empty to submit): ')
104
- break if name.empty?
105
- value = ask_for_primitive('Value: ')
106
-
107
- template = template.fill_field name, value
108
- end
94
+ def create_item
95
+ fill_and_submit_template collection.template,
96
+ 'Fill the template to create a new item.'
97
+ end
109
98
 
110
- make_request template.href, template.convert_to_json, template.method
99
+ def update(item)
100
+ fill_and_submit_template collection.item_template(item),
101
+ 'Fill the template to update the item.'
111
102
  end
112
103
 
113
104
  def print_request
@@ -147,8 +138,8 @@ module Leif
147
138
  end
148
139
  end
149
140
 
150
- def print_template(template = collection.template, label = 'Template')
151
- banner label do |out|
141
+ def print_template(template = collection.template)
142
+ banner 'Template' do |out|
152
143
  out.print JSON.pretty_generate(template).lines
153
144
  end
154
145
  end
@@ -270,7 +261,6 @@ EOS
270
261
  when 'r', 'root' then get_root
271
262
  when 'f', 'follow' then follow_link(collection, *args)
272
263
  when 'create' then create_item
273
- when 'update' then update_item
274
264
 
275
265
  when 'request' then print_request; get_next_action
276
266
  when 'response' then print_response; get_next_action
@@ -301,12 +291,12 @@ EOS
301
291
  [ input.first, input[1..-1] ]
302
292
  end
303
293
 
304
- def ask_for_primitive(message)
305
- value = ask(message)
294
+ def convert_to_primitive(value)
306
295
  case value
307
- when 'null', 'nil' then nil
308
- when '"null"' then 'null'
309
- when '"nil"' then 'nil'
296
+ when 'null', 'nil', '' then nil
297
+ when '"null"' then 'null'
298
+ when '"nil"' then 'nil'
299
+ when '""' then ''
310
300
 
311
301
  when 'true' then true
312
302
  when 'false' then false
@@ -47,6 +47,8 @@ module Leif
47
47
  end
48
48
 
49
49
  class Template < SimpleDelegator
50
+ include Enumerable
51
+
50
52
  attr_accessor :href, :method
51
53
 
52
54
  def initialize(template, href, method)
@@ -55,6 +57,10 @@ module Leif
55
57
  super template
56
58
  end
57
59
 
60
+ def each(&block)
61
+ convert_to_json.each(&block)
62
+ end
63
+
58
64
  def convert_to_json
59
65
  fetch('data').each_with_object({}) do |datum, json|
60
66
  json[datum['name']] = datum['value']
data/lib/leif/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Leif
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Marburger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-10 00:00:00.000000000 Z
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday