notifications-ruby-client 1.0.0 → 1.1.1

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: cfd87a0ae55ca5a8d843a19bd9ffc99959ca646f
4
- data.tar.gz: 48c8ed194a9364549035cdfe410103c22aa3988f
3
+ metadata.gz: 526cd293f41883133d625d11f5ec463e437cd7a5
4
+ data.tar.gz: a1cfba8086a71c42f4ad27830e713005d1e667d9
5
5
  SHA512:
6
- metadata.gz: 048a94ca3bd1fe8d9c16fe91a24f8fe509e23119d4f4a86fd9fca38293cc5a829f5c40cef58d3c3630084984b7274f997cc416db0a0056e79d2a50f414493058
7
- data.tar.gz: 04c883580688bd5a6e66ccb14d4abfb266e72f77880776c8ea1c435ae61e873c90b6228e2a9b0ec7b4e0a6f542a4e894156b31c4bba7b7d816928a2218155e3a
6
+ metadata.gz: 0dc3d6e520d552d4bbf162258783308f7040db46304bd493563d09e6387638a334feac1930edaa6b8d91786e3619d12dc86cc0d4ee1e2756c509c69908fcf23a
7
+ data.tar.gz: 5222d707f9cb24b316466976ca2c447eeac5a4a1ee65bdc2cf105862c6d2d8fb0a03aec533f9f86e9af9897882f1210a7eebbf50cb4410e091c2bb17a3bc2de3
data/.gitignore CHANGED
@@ -10,5 +10,8 @@
10
10
  .DS_Store
11
11
  /vendor
12
12
  environment.sh
13
+ docker.env
13
14
  /.idea/
14
- /.idea/vcs.xml
15
+ /.idea/vcs.xml
16
+ docker.env
17
+ vendor
data/Makefile ADDED
@@ -0,0 +1,68 @@
1
+ .DEFAULT_GOAL := help
2
+ SHELL := /bin/bash
3
+
4
+ DOCKER_BUILDER_IMAGE_NAME = govuk/notify-ruby-client-builder
5
+
6
+ BUILD_TAG ?= notifications-ruby-client-manual
7
+
8
+ DOCKER_CONTAINER_PREFIX = ${USER}-${BUILD_TAG}
9
+
10
+ .PHONY: help
11
+ help:
12
+ @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
13
+
14
+ .PHONY: dependencies
15
+ dependencies: ## Install build dependencies
16
+ bundle install --path=vendor/bundle --binstubs=vendor/bin
17
+
18
+ .PHONY: build
19
+ build: dependencies ## Build project
20
+
21
+ .PHONY: test
22
+ test: ## Run tests
23
+ bundle exec rake spec
24
+
25
+ .PHONY: integration-test
26
+ integration-test: ## Run integration tests
27
+ bundle exec bin/test_client.rb
28
+
29
+ .PHONY: generate-env-file
30
+ generate-env-file: ## Generate the environment file for running the tests inside a Docker container
31
+ bin/generate_docker_env.sh
32
+
33
+ .PHONY: prepare-docker-runner-image
34
+ prepare-docker-runner-image: ## Prepare the Docker builder image
35
+ make -C docker build
36
+
37
+ .PHONY: build-with-docker
38
+ build-with-docker: prepare-docker-runner-image ## Build inside a Docker container
39
+ docker run -i --rm \
40
+ --name "${DOCKER_CONTAINER_PREFIX}-build" \
41
+ -v `pwd`:/var/project \
42
+ ${DOCKER_BUILDER_IMAGE_NAME} \
43
+ make build
44
+
45
+ .PHONY: test-with-docker
46
+ test-with-docker: prepare-docker-runner-image generate-env-file ## Run tests inside a Docker container
47
+ docker run -i --rm \
48
+ --name "${DOCKER_CONTAINER_PREFIX}-test" \
49
+ -v `pwd`:/var/project \
50
+ --env-file docker.env \
51
+ ${DOCKER_BUILDER_IMAGE_NAME} \
52
+ make test
53
+
54
+ .PHONY: integration-test-with-docker
55
+ integration-test-with-docker: prepare-docker-runner-image generate-env-file ## Run integration tests inside a Docker container
56
+ docker run -i --rm \
57
+ --name "${DOCKER_CONTAINER_PREFIX}-integration-test" \
58
+ -v `pwd`:/var/project \
59
+ --env-file docker.env \
60
+ ${DOCKER_BUILDER_IMAGE_NAME} \
61
+ make integration-test
62
+
63
+ .PHONY: clean-docker-containers
64
+ clean-docker-containers: ## Clean up any remaining docker containers
65
+ docker rm -f $(shell docker ps -q -f "name=${DOCKER_CONTAINER_PREFIX}") 2> /dev/null || true
66
+
67
+ clean:
68
+ rm -rf vendor
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  API client for GOV.UK Notify written in Ruby.
4
4
 
5
- [![Build Status](https://travis-ci.org/alphagov/notifications-ruby-client.svg?branch=master)](https://travis-ci.org/alphagov/notifications-ruby-client)
5
+ [![Gem Version](https://badge.fury.io/rb/notifications-ruby-client.svg)](https://badge.fury.io/rb/notifications-ruby-client)
6
6
 
7
7
  ## Installation
8
8
 
@@ -17,20 +17,11 @@ gem install 'notifications-ruby-client'
17
17
  ## Getting started
18
18
 
19
19
  ```ruby
20
- require 'notifications-ruby-client'
21
- client = Notifications::Client.new(service_id, secret_id)
20
+ require 'notifications/client'
21
+ client = Notifications::Client.new(api_key)
22
22
  ```
23
23
 
24
- you can also override api endpoint
25
-
26
- ```ruby
27
- client = Notifications::Client.new(service_id, secret_id, base_url)
28
- client.base_url # => Notifications::Client::PRODUCTION_BASE_URL
29
- ```
30
-
31
- Generate an API key by logging in to GOV.UK Notify [GOV.UK Notify](https://www.notifications.service.gov.uk) and going to the API integration page.
32
-
33
- You will find your service ID on the API integration page.
24
+ Generate an API key by logging in to GOV.UK Notify [GOV.UK Notify](https://www.notifications.service.gov.uk) and going to the **API integration** page.
34
25
 
35
26
  ### Send a message
36
27
 
@@ -156,4 +147,4 @@ e.message # => Invalid credentials
156
147
  </td>
157
148
  </tr>
158
149
  </tbody>
159
- </table>
150
+ </table>
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -eo pipefail
4
+
5
+ function exit_with_msg {
6
+ echo $1
7
+ exit $2
8
+ }
9
+
10
+ echo -n "" > docker.env
11
+
12
+ env_vars=(
13
+ NOTIFY_API_URL
14
+ SERVICE_ID
15
+ API_KEY
16
+ FUNCTIONAL_TEST_EMAIL
17
+ FUNCTIONAL_TEST_NUMBER
18
+ EMAIL_TEMPLATE_ID
19
+ SMS_TEMPLATE_ID
20
+ )
21
+
22
+ for env_var in "${env_vars[@]}"; do
23
+ echo "${env_var}=${!env_var}" >> docker.env
24
+ done
data/bin/test_client.rb CHANGED
@@ -11,18 +11,20 @@ def main
11
11
  test_get_notification_by_id_endpoint(client, email_notification.id, 'email')
12
12
  test_get_notification_by_id_endpoint(client, sms_notification.id, 'sms')
13
13
  test_get_all_notifications(client, sms_notification.id, email_notification.id)
14
- p 'ruby client functional tests pass'
14
+ p 'ruby client integration tests pass'
15
15
  exit 0
16
16
  end
17
17
 
18
18
  def test_send_email_endpoint(client)
19
- email_resp = client.send_email(to: ENV['FUNCTIONAL_TEST_EMAIL'], template: ENV['EMAIL_TEMPLATE_ID'])
19
+ email_resp = client.send_email(to: ENV['FUNCTIONAL_TEST_EMAIL'], template: ENV['EMAIL_TEMPLATE_ID'],
20
+ personalisation:Hash["name", "some name"])
20
21
  test_notification_response_data_type(email_resp, 'email')
21
22
  email_resp
22
23
  end
23
24
 
24
25
  def test_send_sms_endpoint(client)
25
- sms_resp = client.send_sms(to: ENV['FUNCTIONAL_TEST_NUMBER'], template: ENV['SMS_TEMPLATE_ID'])
26
+ sms_resp = client.send_sms(to: ENV['FUNCTIONAL_TEST_NUMBER'], template: ENV['SMS_TEMPLATE_ID'],
27
+ personalisation:Hash["name", "some name"])
26
28
  test_notification_response_data_type(sms_resp, 'sms')
27
29
  sms_resp
28
30
  end
data/docker/Dockerfile ADDED
@@ -0,0 +1,20 @@
1
+ FROM ruby:2.3.1-slim
2
+
3
+ RUN \
4
+ echo "Install Debian packages" \
5
+ && apt-get update \
6
+ && apt-get install -y --no-install-recommends \
7
+ make \
8
+ curl \
9
+ git \
10
+
11
+ && echo "Clean up" \
12
+ && rm -rf /var/lib/apt/lists/* /tmp/*
13
+
14
+ ENV PATH=/var/project/vendor/bin:$PATH \
15
+ BUNDLE_PATH="/var/project/vendor/bundle" \
16
+ BUNDLE_BIN="/var/project/vendor/bin" \
17
+ BUNDLE_APP_CONFIG="/var/project/.bundle"
18
+
19
+
20
+ WORKDIR /var/project
data/docker/Makefile ADDED
@@ -0,0 +1,10 @@
1
+ .DEFAULT_GOAL := help
2
+ SHELL := /bin/bash
3
+
4
+ .PHONY: help
5
+ help:
6
+ @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
7
+
8
+ .PHONY: build
9
+ build:
10
+ docker build --pull -t govuk/notify-ruby-client-builder .
@@ -3,7 +3,7 @@ require "notifications/client/speaker"
3
3
  require "notifications/client/notification"
4
4
  require "notifications/client/response_notification"
5
5
  require "notifications/client/notifications_collection"
6
- require 'active_support/core_ext/module/delegation'
6
+ require "forwardable"
7
7
 
8
8
  module Notifications
9
9
  class Client
@@ -11,9 +11,8 @@ module Notifications
11
11
 
12
12
  PRODUCTION_BASE_URL = "https://api.notifications.service.gov.uk".freeze
13
13
 
14
- delegate :base_url,
15
- :base_url=,
16
- to: :speaker
14
+ extend Forwardable
15
+ def_delegators :speaker, :service_id, :secret_token, :base_url, :base_url=
17
16
 
18
17
  ##
19
18
  # @see Notifications::Client::Speaker#initialize
@@ -7,6 +7,8 @@ module Notifications
7
7
  class Client
8
8
  class Speaker
9
9
  attr_reader :base_url
10
+ attr_reader :service_id
11
+ attr_reader :secret_token
10
12
 
11
13
  BASE_PATH = "/notifications".freeze
12
14
  USER_AGENT = "NOTIFY-API-RUBY-CLIENT/#{Notifications::Client::VERSION}".freeze
@@ -18,10 +20,20 @@ module Notifications
18
20
  # secret
19
21
  # @param base_url [String] host URL. This is
20
22
  # the address to perform the requests
21
- def initialize(service_id, secret_token, base_url = nil)
22
- @service_id = service_id
23
- @secret_token = secret_token
24
- @base_url = base_url || PRODUCTION_BASE_URL
23
+ def initialize(service_id, secret_token = nil, base_url = nil)
24
+ if secret_token == nil and base_url == nil
25
+ @service_id = service_id[service_id.length - 73..service_id.length - 38]
26
+ @secret_token = service_id[service_id.length - 36..service_id.length]
27
+ @base_url = PRODUCTION_BASE_URL
28
+ elsif secret_token.start_with?("http") and base_url == nil
29
+ @service_id = service_id[service_id.length - 73..service_id.length - 38]
30
+ @secret_token = service_id[service_id.length - 36..service_id.length]
31
+ @base_url = secret_token
32
+ else
33
+ @service_id = service_id
34
+ @secret_token = secret_token[secret_token.length - 36..secret_token.length]
35
+ @base_url = base_url || PRODUCTION_BASE_URL
36
+ end
25
37
  end
26
38
 
27
39
  ##
@@ -1,5 +1,5 @@
1
1
  module Notifications
2
2
  class Client
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bitzesty
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-08-31 00:00:00.000000000 Z
12
+ date: 2016-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jwt
@@ -119,14 +119,17 @@ extra_rdoc_files: []
119
119
  files:
120
120
  - ".gitignore"
121
121
  - ".rspec"
122
- - ".travis.yml"
123
122
  - Gemfile
124
123
  - LICENSE
124
+ - Makefile
125
125
  - README.md
126
126
  - Rakefile
127
127
  - bin/console
128
+ - bin/generate_docker_env.sh
128
129
  - bin/setup
129
130
  - bin/test_client.rb
131
+ - docker/Dockerfile
132
+ - docker/Makefile
130
133
  - lib/notifications/client.rb
131
134
  - lib/notifications/client/notification.rb
132
135
  - lib/notifications/client/notifications_collection.rb
@@ -154,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
157
  version: '0'
155
158
  requirements: []
156
159
  rubyforge_project:
157
- rubygems_version: 2.5.1
160
+ rubygems_version: 2.6.7
158
161
  signing_key:
159
162
  specification_version: 4
160
163
  summary: Ruby client for GOV.UK Notifications API
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.2