cdg-services 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +31 -3
- data/lib/cdg/services.rb +34 -5
- data/lib/cdg/services/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be75427458f4ca247038ec948efcdd3e5e427be8
|
4
|
+
data.tar.gz: b390047cf4e3fb287b25ee3b7de841edd3178b14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5641e845251af0794799b5e46fff6fac4a12e9907ccd5316962f30376f9fe757388c453dc09c0b265b7976a950aeb9458a14e58674bc687e4017835eb2b7c62
|
7
|
+
data.tar.gz: d838926f1150abf76b48f1933340e97ca9df86ae3603f7b2e55963d32f969d8d30d5a68e15aba8dbd3260b44c7c240d0ebaf45c18f4355bafe91b644e7f0f30a
|
data/README.md
CHANGED
@@ -26,23 +26,51 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
+
#### CDG::Services.get_ios_version
|
30
|
+
|
29
31
|
Get the latest app version of any iOS app; `app_id` is the id of the app in the form of numerics, eg. `12345678`.
|
30
32
|
```ruby
|
31
33
|
CDG::Services.get_ios_version(app_id: app_id)
|
32
34
|
```
|
33
|
-
|
35
|
+
#### CDG::Services.get_android_version
|
34
36
|
|
35
37
|
Get the latest app version of any Android app; `app_id` is the id of the app in the form of `com.package.name`.
|
36
38
|
```ruby
|
37
39
|
CDG::Services.get_android_version(app_id: app_id)
|
38
40
|
```
|
39
41
|
|
42
|
+
#### CDG::Services.ping_slack
|
40
43
|
|
41
|
-
Send a message to any slack channel via a Slack webhook, eg. `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`. See how to set up a [Slack webhook](https://api.slack.com/incoming-webhooks).
|
44
|
+
Send a message as an attachment to any slack channel via a Slack webhook, eg. `https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX`. See how to set up a [Slack webhook](https://api.slack.com/incoming-webhooks) and send message as [attachment](https://api.slack.com/docs/message-attachments).
|
42
45
|
|
43
46
|
Set the webhook in your application's environment variable with the name `SLACK_URL`. This gem access the webhook using `ENV['SLACK_URL']`.
|
44
47
|
```ruby
|
45
|
-
CDG::Services.
|
48
|
+
CDG::Services.ping_slack(
|
49
|
+
text: "test", # only this is mandatory
|
50
|
+
channel: "#pings-tests",
|
51
|
+
username: "test",
|
52
|
+
color: ["good", "warning", "danger", "#af3131", "af3131"].sample,
|
53
|
+
title: "test title",
|
54
|
+
title_link: "https://www.codigo.co/",
|
55
|
+
pretext: "test pretext",
|
56
|
+
fields: [
|
57
|
+
{
|
58
|
+
title: "field 1 title",
|
59
|
+
value: "field 1 value",
|
60
|
+
short: true,
|
61
|
+
},
|
62
|
+
{
|
63
|
+
title: "field 2 title",
|
64
|
+
value: "field 2 value",
|
65
|
+
short: true,
|
66
|
+
},
|
67
|
+
{
|
68
|
+
title: "field 3 title",
|
69
|
+
value: "This field 3 value is super loooooo oooooooooooooo ooooooooooooooo oooooooooooooong",
|
70
|
+
short: false,
|
71
|
+
},
|
72
|
+
]
|
73
|
+
)
|
46
74
|
```
|
47
75
|
|
48
76
|
## Development
|
data/lib/cdg/services.rb
CHANGED
@@ -35,22 +35,51 @@ module CDG
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def self.ping_slack!
|
38
|
+
def self.ping_slack!(
|
39
|
+
webhook: ENV['SLACK_URL'],
|
40
|
+
color: "5bc0de", # default boostrap color for info
|
41
|
+
title: nil,
|
42
|
+
title_link: nil,
|
43
|
+
pretext: nil,
|
44
|
+
text: ,
|
45
|
+
fields: nil,
|
46
|
+
channel: nil,
|
47
|
+
username: nil)
|
39
48
|
begin
|
49
|
+
if fields && !fields.is_a?(Array)
|
50
|
+
raise ArgumentError, "wrong argument type for \"fields\"; should be an array"
|
51
|
+
end
|
52
|
+
|
40
53
|
uri = URI(webhook)
|
41
54
|
|
42
55
|
resp = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
43
56
|
req = Net::HTTP::Post.new(uri)
|
44
57
|
req['Content-Type'] = 'application/json'
|
45
58
|
|
46
|
-
|
47
|
-
|
59
|
+
attachment = {}
|
60
|
+
attachment[:text] = text
|
61
|
+
attachment[:color] = color if color
|
62
|
+
attachment[:title] = title if title
|
63
|
+
attachment[:title_link] = title_link if title_link
|
64
|
+
attachment[:pretext] = pretext if pretext
|
65
|
+
attachment[:fields] = fields if fields
|
66
|
+
|
67
|
+
body = { attachments: [attachment] }
|
48
68
|
body[:channel] = channel if channel
|
49
69
|
body[:username] = username if username
|
50
|
-
# TODO custom icon_emoji?
|
51
70
|
|
52
71
|
req.body = body.to_json
|
53
|
-
http.request(req)
|
72
|
+
resp = http.request(req)
|
73
|
+
|
74
|
+
## TODO need to find a better way handle response body?
|
75
|
+
if resp.is_a?(Net::HTTPNotFound)
|
76
|
+
case resp.body
|
77
|
+
when "channel_not_found"
|
78
|
+
raise ArgumentError, "slack channel is not found"
|
79
|
+
else
|
80
|
+
# TODO
|
81
|
+
end
|
82
|
+
end
|
54
83
|
end
|
55
84
|
rescue => e
|
56
85
|
raise e
|
data/lib/cdg/services/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdg-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vic-L
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|