cordial 0.1.1 → 0.1.2

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
- SHA1:
3
- metadata.gz: e83d1045ce86b44e14a66dfc67a56f1e70e8b995
4
- data.tar.gz: bbb0cdcaae5b4db569edad3a38f4c0dc26519f06
2
+ SHA256:
3
+ metadata.gz: a30b36da7c22388a85a10b02e98f79268c07989a31e98f62b9f57e6dc9313b77
4
+ data.tar.gz: ba66580215145c937bbdf8fd002a73384e3206137d6cd96b41e1a4683aacff6d
5
5
  SHA512:
6
- metadata.gz: cda227ed6d6eefb76cffb11f7cd141490e3dec7cf00692a01b6a1de725e90d9549de97fcb14a68216dac9b844d5b4b9e74341cef209514bbc5596e852b1c95cb
7
- data.tar.gz: b7d98185f7a344633b055e14354b617f01f6de01c2f6123ce3cafcd946d78d6bfe7002025057eb0431585cd869216faf03eaac9091cc46006ae8a64f13376740
6
+ metadata.gz: 88fead131ea85e1499240b3016a705c8abf855295891151af79c53661267ba8dba5d5f9ea45817bcefa54115fccfa76c33fd87373fb3951d57cd358d4614a18a
7
+ data.tar.gz: 4f8154e2389142ba92e4bb90253ce84351a7991eb6d88d35e5466c96e5607eed13ee60c28443918c4ecb6a7c707bde9977da52a6735b24ad58ce8bc0c6cda696
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.5.1
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
- sudo: false
2
1
  language: ruby
3
- rvm:
4
- - 2.3.4
5
- before_install: gem install bundler -v 1.15.3
2
+
3
+ before_script:
4
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
5
+ - chmod +x ./cc-test-reporter
6
+ - ./cc-test-reporter before-build
7
+
8
+ after_script:
9
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Cordial
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/cordial`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [ ![Codeship Status for MeUndies/cordial](https://app.codeship.com/projects/ecb6fbe0-2a65-0136-d9ce-769c4cc8653c/status?branch=master)](https://app.codeship.com/projects/287555)
4
+ [![Gem Version](https://badge.fury.io/rb/cordial.svg)](https://badge.fury.io/rb/cordial)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a53de2aaf1773c8cfb06/maintainability)](https://codeclimate.com/github/MeUndies/cordial/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a53de2aaf1773c8cfb06/test_coverage)](https://codeclimate.com/github/MeUndies/cordial/test_coverage)
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
8
+ A ruby gem to interact with the [Cordial API](https://api.cordial.io/docs/v1/).
6
9
 
7
10
  ## Installation
8
11
 
@@ -20,9 +23,17 @@ Or install it yourself as:
20
23
 
21
24
  $ gem install cordial
22
25
 
26
+ ```ruby
27
+ Cordial.configure do |config|
28
+ config.api_key = 'your-api-key'
29
+ end
30
+ ```
31
+
23
32
  ## Usage
24
33
 
25
- TODO: Write usage instructions here
34
+ ```ruby
35
+ Cordial::Contact.create(email: 'hello@world')
36
+ ```
26
37
 
27
38
  ## Development
28
39
 
@@ -32,4 +43,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
43
 
33
44
  ## Contributing
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cordial.
46
+ Bug reports and pull requests are welcome!
data/cordial.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "httparty", "~> 0.16"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.15"
25
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake", "~> 12.3"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
27
  spec.add_development_dependency "pry", "~> 0.11"
28
28
  spec.add_development_dependency "dotenv", "~> 2.4"
@@ -6,6 +6,7 @@ module Cordial
6
6
  def client
7
7
  base_uri 'https://api.cordial.io/v1'
8
8
  basic_auth(Cordial.config.api_key, '')
9
+ headers 'Content-Type' => 'application/json'
9
10
  self
10
11
  end
11
12
  end
@@ -1,23 +1,74 @@
1
1
  module Cordial
2
- # https://api.cordial.io/docs/v1/#!/contacts
2
+ # Wraps all interaction with the Contact resource.
3
+ # @see https://api.cordial.io/docs/v1/#!/contacts
3
4
  class Contacts
4
5
  include ::HTTParty
5
6
  extend Client
6
7
 
8
+ # Find a contact.
9
+ # @example Usage
10
+ # Cordial::Contacts.find(email: 'hello@world.earth')
11
+ # @example Response when the contact was found.
12
+ # {
13
+ # "_id" => "111122223334444",
14
+ # "channels" => {
15
+ # "email" => {
16
+ # "address" => "hello@world.earth",
17
+ # "subscribeStatus" => "unsubscribed",
18
+ # "unsubscribedAt" => "2018-05-02T23:35:38+0000"
19
+ # }
20
+ # },
21
+ # "lastModified" => "2018-05-16T22:57:16+0000",
22
+ # "createdAt" => "2018-04-25T19:55:45+0000",
23
+ # "lists" => ["test-list"],
24
+ # "lj" => {
25
+ # "14854" => {
26
+ # "sec" => 1524897139,
27
+ # "usec" => 0
28
+ # }
29
+ # },
30
+ # "listJoinDate" => {
31
+ # "test-list" => "2018-04-28T06:32:19+0000"
32
+ # }
33
+ # }
34
+ #
35
+ # @example Response when the contact was not found.
36
+ # {"error"=>true, "message"=>"record not found"}
7
37
  def self.find(email:)
8
38
  client.get("/contacts/#{email}")
9
39
  end
10
40
 
11
- def self.create(email:, attribute_list:)
41
+ # Create a new contact.
42
+ #
43
+ # If the contact already exists it will be updated.
44
+ # @example Usage.
45
+ # Cordial::Contacts.create(
46
+ # email: 'hello@world.earth',
47
+ # attribute_list: {
48
+ # some_attribute: 'your-custom-value'
49
+ # },
50
+ # subscribe_status: 'subscribed'
51
+ # )
52
+ def self.create(email:, attribute_list: {}, subscribe_status: nil)
12
53
  client.post('/contacts', body: {
13
54
  channels: {
14
55
  email: {
15
- address: email
16
- }
17
- }
18
- }.merge(attribute_list))
56
+ address: email,
57
+ subscribeStatus: subscribe_status
58
+ }.compact
59
+ },
60
+ forceSubscribe: subscribe_status == 'subscribed' || nil
61
+ }.compact.merge(attribute_list).to_json)
19
62
  end
20
63
 
64
+ # Unsubscribe a contact.
65
+ #
66
+ # @param channel [String] The channel to unsubscribe, defaults to `email`
67
+ # @see https://support.cordial.com/hc/en-us/articles/115001319432-Channels-Overview
68
+ # @example Usage. Default channel.
69
+ # Cordial::Contacts.unsubscribe(
70
+ # email: 'hello@world.earth'
71
+ # )
21
72
  def self.unsubscribe(email:, channel: 'email')
22
73
  client.put("/contacts/#{email}/unsubscribe/#{channel}")
23
74
  end
@@ -0,0 +1,61 @@
1
+ module Cordial
2
+ # Wraps all interaction with the Product resource.
3
+ # @see https://api.cordial.io/docs/v1/#!/products
4
+ class Products
5
+ include ::HTTParty
6
+ extend Client
7
+
8
+ # Find a product.
9
+ # @example Usage
10
+ # Cordial::products.find(product_id: 1)
11
+ # @example Response when the product was found.
12
+ # {
13
+ # "_id"=>"5b28275fe1dc0fa0c872abec",
14
+ # "productID"=>"1",
15
+ # "productName"=>"Test Product",
16
+ # "price"=>10,
17
+ # "variants"=>[
18
+ # {
19
+ # "sku"=>"123456789",
20
+ # "attr"=>{"color"=>"blue", "size"=>"Large"},
21
+ # "qty"=>"10"}
22
+ # ],
23
+ # "accountID"=>645,
24
+ # "totalQty"=>10,
25
+ # "lm"=>"2018-06-18T21:42:55+0000",
26
+ # "ct"=>"2018-06-18T21:42:55+0000"
27
+ # }
28
+ #
29
+ # @example Response when the product was not found.
30
+ # {"error"=>true, "message"=>"record not found"}
31
+ def self.find(id:)
32
+ client.get("/products/#{id}")
33
+ end
34
+
35
+ # Create a new product.
36
+ #
37
+ # If the product already exists it will be updated.
38
+ # @example Usage.
39
+ # Cordial::Products.create(
40
+ # product_id: 1,
41
+ # product_name: 'Test Product',
42
+ # price: 99.99,
43
+ # variants: [{
44
+ # sku: '123',
45
+ # attr: {
46
+ # color: 'red',
47
+ # size: 'L'
48
+ # }
49
+ # }]
50
+ # )
51
+ def self.create(id:, name:, price:, variants:)
52
+ client.post('/products',
53
+ body: {
54
+ productID: id,
55
+ productName: name,
56
+ price: price,
57
+ variants: variants
58
+ }.to_json)
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module Cordial
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'.freeze
3
3
  end
data/lib/cordial.rb CHANGED
@@ -2,6 +2,7 @@ require "httparty"
2
2
  require "cordial/version"
3
3
  require "cordial/client"
4
4
  require "cordial/contacts"
5
+ require "cordial/products"
5
6
 
6
7
  module Cordial
7
8
  class << self
@@ -14,6 +15,6 @@ module Cordial
14
15
  end
15
16
 
16
17
  class Configuration
17
- attr_accessor :api_key, :api_url
18
+ attr_accessor :api_key
18
19
  end
19
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cordial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '12.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +130,7 @@ files:
130
130
  - lib/cordial.rb
131
131
  - lib/cordial/client.rb
132
132
  - lib/cordial/contacts.rb
133
+ - lib/cordial/products.rb
133
134
  - lib/cordial/version.rb
134
135
  homepage: https://github.com/MeUndies/cordial
135
136
  licenses:
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.5.2
155
+ rubygems_version: 2.7.6
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: Cordial API Client