cdg-services 0.0.1 → 0.0.2

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: f65edfe2bf757f62b6571da3f5434d81e8bacecc
4
- data.tar.gz: 74f7996b2f294adb7075c531c94a1c3098ebc410
3
+ metadata.gz: aaa8ff22fb0a0aac4fdd1d7ecefbe1990cf35d9d
4
+ data.tar.gz: 16a868e0632c73d9be64f5e49fa29ef6f64a03a9
5
5
  SHA512:
6
- metadata.gz: bf1b25102cb84298aa7d25b1c732687a51490f1d2d359b9f3453cf905b1c1655e694f7826a58a32fc75b2bf1568097be33bfdcbde3c2a413bd371f4aeb9d41f3
7
- data.tar.gz: 907eaf6642c25a078cc729f6834c78160c81acfcffb77d5e68af10dc989590460ac0f4a378f5d852398824cddc468b407ed3acce9e7a2e2455fe5f12e4002b12
6
+ metadata.gz: 583b196d9d636cb3fed5dfe8ab93a6c67c8d5c1273fb044e19722a59ec2ed1fc5afa988e2d1454ecbe7b6fed0db6d81827c7b0d2d41011442caf3eaecc83c449
7
+ data.tar.gz: fa01d0c139db7191b837d35e5840321970fd9467b2918e1a8b60972140cb4cbec6a1cf7111d6e989bf2ceb449f16da367f8e2876d128620d09094a611f19e176
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.0.2] - 2017-07-07
10
+ ### Added
11
+ - Add method(`CDG::Services.ping_slack!`) to send notification to slack with some custom params
12
+
13
+ ### Changed
14
+ - Rename method `CDG::Services.GetIOSVersion` to `CDG::Services.get_ios_version` to follow ruby naming conventions
15
+ - Rename method `CDG::Services.GetAndroidVersion` to `CDG::Services.get_android_version` to follow ruby naming conventions
16
+
17
+ ## [0.0.1] - 2017-07-06
18
+ ### Added
19
+ - Add method (`CDG::Services.GetIOSVersion`) which fetches the latest ios app's version base on app id via a net/http call
20
+ - Add method (`CDG::Services.GetAndroidVersion`) which fetches the latest android app's version base on an app id via a net/http call
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # CDG::Services
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cdg/services`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Codigo - Ruby on Rails Team's common services.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ We adopted a microservice architecture in devising the approach of usage of this gem.
6
+
7
+ These services are functions that are expected to be commonly used among our projects.
8
+
9
+ This library serves to accumulate all this knowledge and speed up development without compromising quality and accuracy.
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,7 +26,24 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ 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
+ ```ruby
31
+ CDG::Services.get_ios_version(app_id: app_id)
32
+ ```
33
+
34
+
35
+ 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
+ ```ruby
37
+ CDG::Services.get_android_version(app_id: app_id)
38
+ ```
39
+
40
+
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).
42
+
43
+ Set the webhook in your application's environment variable with the name `SLACK_URL`. This gem access the webhook using `ENV['SLACK_URL']`.
44
+ ```ruby
45
+ CDG::Services.get_android_version(app_id: app_id)
46
+ ```
26
47
 
27
48
  ## Development
28
49
 
data/lib/cdg/services.rb CHANGED
@@ -9,7 +9,7 @@ module CDG
9
9
 
10
10
  module Services
11
11
 
12
- def self.GetIOSVersion app_id: # eg 123456789
12
+ def self.get_ios_version app_id: # eg 123456789
13
13
  resp = JSON.parse Net::HTTP.get(URI("https://itunes.apple.com/lookup?id=#{app_id}"))
14
14
  results = resp["results"]
15
15
 
@@ -20,7 +20,7 @@ module CDG
20
20
  end
21
21
  end
22
22
 
23
- def self.GetAndroidVersion app_id: # eg sg.codigo.app_name
23
+ def self.get_android_version app_id: # eg sg.codigo.app_name
24
24
  begin
25
25
  resp = Nokogiri::HTML(open("https://play.google.com/store/apps/details?id=#{ app_id }&hl=en"))
26
26
  elements = resp.css("div[class='content'][itemprop='softwareVersion']")
@@ -33,7 +33,28 @@ module CDG
33
33
  rescue OpenURI::HTTPError => e
34
34
  return nil
35
35
  end
36
+ end
36
37
 
38
+ def self.ping_slack! webhook: ENV['SLACK_URL'], message:, channel: nil, username: nil
39
+ begin
40
+ uri = URI(webhook)
41
+
42
+ resp = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
43
+ req = Net::HTTP::Post.new(uri)
44
+ req['Content-Type'] = 'application/json'
45
+
46
+ body = {}
47
+ body[:text] = message
48
+ body[:channel] = channel if channel
49
+ body[:username] = username if username
50
+ # TODO custom icon_emoji?
51
+
52
+ req.body = body.to_json
53
+ http.request(req)
54
+ end
55
+ rescue => e
56
+ raise e
57
+ end
37
58
  end
38
59
 
39
60
  end
@@ -1,5 +1,5 @@
1
1
  module CDG
2
2
  module Services
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
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.1
4
+ version: 0.0.2
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-05 00:00:00.000000000 Z
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -94,6 +94,7 @@ files:
94
94
  - ".gitignore"
95
95
  - ".rspec"
96
96
  - ".travis.yml"
97
+ - CHANGELOG.md
97
98
  - CODE_OF_CONDUCT.md
98
99
  - Gemfile
99
100
  - LICENSE.txt
@@ -104,7 +105,6 @@ files:
104
105
  - cdg-services.gemspec
105
106
  - lib/cdg/services.rb
106
107
  - lib/cdg/services/version.rb
107
- - lib/cdg/version.rb
108
108
  homepage: https://github.com/sgcodigo/cdg-services
109
109
  licenses:
110
110
  - MIT
data/lib/cdg/version.rb DELETED
@@ -1,5 +0,0 @@
1
- module CDG
2
- module Services
3
- VERSION = "0.0.1"
4
- end
5
- end