nidobata 0.3.0 → 0.5.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
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9406b4676173d12fe4894d19c005421fa6b76b71
4
- data.tar.gz: 18451da692b9cbd9a6ed160540702b8e5df0a827
3
+ metadata.gz: 87bff0f98393cd9b66a00a0a76d819cc24502244
4
+ data.tar.gz: 89cf328c7c7d4581c0a4d34ab3f0e7f994be197e
5
5
  SHA512:
6
- metadata.gz: 493c84f5dce90d5ebc1eeefbdbede36613b66caabc22ac9b6773465b9eab6d705aff9f3aaaf2207373e4d37a681a033823c2ced60c9183c5e631c65b56673a6a
7
- data.tar.gz: b117612bb6fd0463d9d61c2022947b1b2b8919e9a92845681c9dc3c0d9df0737f30fe09d616dbe126fb31dd4b37b582270eb649c39d26afad449f88e4fd2a3db
6
+ metadata.gz: 82b9b44718a22d560e87efa4e95668a954d5845349576d2ad9bffff9f1fc91affba1973798b898a4c13349e7c59d31a4e1e6236ea0d457103456d4d8ce1f744f
7
+ data.tar.gz: 62b19ee5ef18c19d2909b30ba512dc9c6313b132047a2a1d31837f80c9a7daee9972431bdf94dbba34907ff92db104b9760506d4155b63befc54093202a322e3
data/README.md CHANGED
@@ -19,10 +19,11 @@ Password: ⏎
19
19
  $ uname -a | nidobata post my-org-slug my-room
20
20
  ```
21
21
 
22
- `--pre` option surrounds input with `<pre></pre>`.
22
+ `--pre` option surrounds input with triple tildes(`~~~`) and syntax name.
23
+ :warning: It does not work when including triple backquotes or triple tildes in input text :warning:
23
24
 
24
25
  ```
25
- $ cat README.md | nidobata post my-org-slug my-room --pre
26
+ $ cat README.md | nidobata post my-org-slug my-room --pre markdown
26
27
  ```
27
28
 
28
29
  ## Development
@@ -1,3 +1,3 @@
1
1
  module Nidobata
2
- VERSION = '0.3.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/nidobata.rb CHANGED
@@ -14,16 +14,31 @@ module Nidobata
14
14
  def init
15
15
  email = ask('Email:')
16
16
  password = ask('Password:', echo: false)
17
+ puts
17
18
  data = {grant_type: 'password', username: email, password: password}
18
-
19
- token = JSON.parse(http.post('/oauth/token', data.to_json, {'Content-Type' => 'application/json'}).tap(&:value).body)['access_token']
20
- netrc = Netrc.read
21
- netrc[IDOBATA_URL.host] = email, token
22
- netrc.save
19
+ res = http.post('/oauth/token', data.to_json, {'Content-Type' => 'application/json'})
20
+
21
+ case res
22
+ when Net::HTTPSuccess
23
+ token = JSON.parse(res.body)['access_token']
24
+ netrc = Netrc.read
25
+ netrc[IDOBATA_URL.host] = email, token
26
+ netrc.save
27
+ when Net::HTTPUnauthorized
28
+ abort 'Authentication failed. You may have entered wrong Email or Password.'
29
+ else
30
+ abort <<-EOS
31
+ Failed to initialize.
32
+ Status: #{res.code}
33
+ Body:
34
+ #{res.body}
35
+ EOS
36
+ end
23
37
  end
24
38
 
25
- desc 'post ORG_SLUG ROOM_NAME [MESSAGE] [--pre]', 'Post a message from stdin or 2nd argument.'
26
- option :pre, type: :boolean
39
+ desc 'post ORG_SLUG ROOM_NAME [MESSAGE] [--pre] [--title]', 'Post a message from stdin or 2nd argument.'
40
+ option :pre, type: :string, lazy_default: '', desc: 'can be used syntax highlight if argument exists'
41
+ option :title, type: :string, default: nil
27
42
  def post(slug, room_name, message = $stdin.read)
28
43
  abort 'Message is required.' unless message
29
44
  ensure_api_token
@@ -31,12 +46,9 @@ module Nidobata
31
46
  rooms = JSON.parse(http.get("/api/rooms?organization_slug=#{slug}&room_name=#{room_name}", default_headers).tap(&:value).body)
32
47
  room_id = rooms['rooms'][0]['id']
33
48
 
34
- payload =
35
- if options[:pre]
36
- {room_id: room_id, source: "<pre>\n#{message}</pre>", format: 'html'}
37
- else
38
- {room_id: room_id, source: message}
39
- end
49
+ message = build_message(message, options)
50
+ payload = {room_id: room_id, source: message}
51
+ payload[:format] = 'markdown' if options[:pre]
40
52
 
41
53
  http.post('/api/messages', payload.to_json, default_headers).value
42
54
  end
@@ -84,6 +96,15 @@ module Nidobata
84
96
  http.use_ssl = IDOBATA_URL.scheme == 'https'
85
97
  }
86
98
  end
99
+
100
+ def build_message(original_message, options)
101
+ return original_message if options.empty?
102
+
103
+ title, pre = options.values_at(:title, :pre)
104
+
105
+ message = pre ? "~~~#{pre}\n#{original_message}\n~~~" : original_message
106
+ title ? "#{title}\n\n#{message}" : message
107
+ end
87
108
  end
88
109
  end
89
110
  end
data/nidobata.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'nidobata/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "nidobata"
8
8
  spec.version = Nidobata::VERSION
9
- spec.authors = ["Hibariya"]
10
- spec.email = ["hibariya@gmail.com"]
9
+ spec.authors = ["Hibariya", "Seiei Miyagi", "Mitsutaka Mimura"]
10
+ spec.email = ["hibariya@gmail.com", "hanachin@gmail.com", "takkanm@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Read stdin and post it into idobata.io.}
13
13
  spec.homepage = 'https://github.com/idobata/nidobata'
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nidobata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hibariya
8
+ - Seiei Miyagi
9
+ - Mitsutaka Mimura
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2017-01-12 00:00:00.000000000 Z
13
+ date: 2017-01-25 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: thor
@@ -69,6 +71,8 @@ dependencies:
69
71
  description:
70
72
  email:
71
73
  - hibariya@gmail.com
74
+ - hanachin@gmail.com
75
+ - takkanm@gmail.com
72
76
  executables:
73
77
  - nidobata
74
78
  extensions: []