portatext 0.0.2 → 1.0.0.pre

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: 50ede6f538968f483c1cbb537ac84e9f88745f41
4
- data.tar.gz: a24b867a6f1d19153295d2882b4c3f9ef5751bad
3
+ metadata.gz: 32954d59d49430b0f104a0609dd4e9ff9fcdea74
4
+ data.tar.gz: d18ce7ded936bc34c1ff77ddaa61f6c1dc8dc896
5
5
  SHA512:
6
- metadata.gz: 2a0dda3ef83a228e9d14ca5a906b6ad1c4a5f9ca33bede9aa88512579af405aca5f11b3b95a99e47dd2a909e1513cd6960778f4628fc8a578bb73a082eb7b831
7
- data.tar.gz: 77ccb360a42737f6c13a46ef897c4f4cb5b54182cb14dfdcaae064c2e00b9aed9e0f1780cad64a5975402a2db7fef7e3d5684d3438b151e2e90586bc13f349ab
6
+ metadata.gz: d95b9c7bd33971d0b47eed960f821498d5e2603cd8656054c4bcf5b6e038fc5d78019dcac80da5500549c6c74bfed746d2e63f1626eda4efe98f19568f437b46
7
+ data.tar.gz: 3e8f29cbd84e2595e5018f258d45ad116ec83dd4123c0b1b3a8e69c72b6e25e92157be3ffdf3ba1052df9e0504ad5e50eacbc3c1fdd1191c25733cc1a98250a3
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  [![License](http://img.shields.io/badge/license-APACHE2-blue.svg)](http://img.shields.io/badge/license-APACHE2-blue.svg)
2
2
  [![Gem Version](https://badge.fury.io/rb/portatext.svg)](https://badge.fury.io/rb/portatext)
3
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/portatext/ruby-sdk/master/frames)
3
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/portatext)
4
4
 
5
5
  [![Build Status](https://travis-ci.org/PortaText/ruby-sdk.svg)](https://travis-ci.org/PortaText/ruby-sdk)
6
6
  [![Coverage Status](https://coveralls.io/repos/PortaText/ruby-sdk/badge.svg?branch=master&service=github)](https://coveralls.io/github/PortaText/ruby-sdk?branch=master)
7
7
  [![Code Climate](https://codeclimate.com/github/PortaText/ruby-sdk/badges/gpa.svg)](https://codeclimate.com/github/PortaText/ruby-sdk)
8
8
  [![Issue Count](https://codeclimate.com/github/PortaText/ruby-sdk/badges/issue_count.svg)](https://codeclimate.com/github/PortaText/ruby-sdk)
9
9
  [![Inline docs](http://inch-ci.org/github/portatext/ruby-sdk.svg?branch=master)](http://inch-ci.org/github/portatext/ruby-sdk)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/remote-exec/command-designer/master/frames)
10
+
11
11
  # ruby-sdk
12
12
  Official Ruby Client for the [PortaText](https://www.portatext.com/) API.
13
13
 
@@ -19,7 +19,9 @@ module PortaText
19
19
  method = method.to_s.split('_').map(&:capitalize)
20
20
  name = "PortaText::Command::Api::#{method.join('')}"
21
21
  class_name = Object.const_get name
22
- class_name.new self
22
+ command = class_name.new
23
+ command.client = self
24
+ command
23
25
  end
24
26
 
25
27
  # rubocop:disable Metrics/MethodLength
@@ -33,6 +35,7 @@ module PortaText
33
35
  true_endpoint, method, headers, body
34
36
  )
35
37
  ret_code, ret_headers, ret_body = @executor.execute descriptor
38
+ @logger.debug "Got: #{ret_code} / #{ret_headers} / #{ret_body}"
36
39
  result = PortaText::Command::Result.new(
37
40
  ret_code, ret_headers, JSON.parse(ret_body)
38
41
  )
@@ -32,12 +32,21 @@ module PortaText
32
32
  http
33
33
  end
34
34
 
35
+ # rubocop:disable Metrics/MethodLength
35
36
  def create_request(uri, method, body)
36
37
  method = method.to_s.capitalize
37
38
  request = Object.const_get("Net::HTTP::#{method}").new uri
38
- request.body = body
39
+ data = /^file:(.*)$/.match(body)
40
+ if data.nil?
41
+ request.body = body
42
+ else
43
+ file = data.captures.shift
44
+ request.content_length = File.size file
45
+ request.body_stream = File.open file, 'r'
46
+ end
39
47
  request
40
48
  end
49
+ # rubocop:enable Metrics/MethodLength
41
50
 
42
51
  def request!(descriptor, http, request)
43
52
  descriptor.headers.each_pair do |k, v|
@@ -0,0 +1,29 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The blacklist endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_blacklist
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Blacklist < Base
11
+ def number(number)
12
+ set :number, number
13
+ end
14
+
15
+ def csv(file)
16
+ set :file, file
17
+ end
18
+
19
+ def endpoint(_method)
20
+ return 'blacklist/contacts' unless @args[:file].nil?
21
+ return 'blacklist' if @args[:number].nil?
22
+ number = @args[:number]
23
+ @args.delete :number
24
+ "blacklist/#{number}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The campaigns/:id/lifecycle endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_campaigns_lifecycle
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class CampaignLifecycle < Base
11
+ def id(id)
12
+ set :id, id
13
+ end
14
+
15
+ def start
16
+ action 'start'
17
+ end
18
+
19
+ def pause
20
+ action 'pause'
21
+ end
22
+
23
+ def resume
24
+ action 'resume'
25
+ end
26
+
27
+ def cancel
28
+ action 'cancel'
29
+ end
30
+
31
+ def endpoint(_method)
32
+ fail 'Campaign id cant be null' if @args[:id].nil?
33
+ id = @args[:id]
34
+ @args.delete :id
35
+ "campaigns/#{id}/lifecycle"
36
+ end
37
+
38
+ private
39
+
40
+ def action(action)
41
+ set :action, action
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,41 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The campaigns endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_campaigns
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Campaigns < Base
11
+ def id(id)
12
+ set :id, id
13
+ end
14
+
15
+ def name(name)
16
+ set :name, name
17
+ end
18
+
19
+ def description(description)
20
+ set :description, description
21
+ end
22
+
23
+ def from(from)
24
+ set :from, from
25
+ end
26
+
27
+ def to_contact_lists(contact_lists)
28
+ set :contact_list_ids, contact_lists
29
+ end
30
+
31
+ def endpoint(_method)
32
+ return 'campaigns' if @args[:id].nil?
33
+ id = @args[:id]
34
+ @args.delete :type
35
+ @args.delete :id
36
+ "campaigns/#{id}"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The cnam endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_cnam
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Cnam < Base
11
+ def for_number(number)
12
+ set :number, number
13
+ end
14
+
15
+ def endpoint(_method)
16
+ fail 'DID number cant be null' if @args[:number].nil?
17
+ number = @args[:number]
18
+ @args.delete :number
19
+ "cnam/#{number}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The contact_lists endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_contact_lists
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class ContactLists < Base
11
+ def id(id)
12
+ set :id, id
13
+ end
14
+
15
+ def name(name)
16
+ set :name, name
17
+ end
18
+
19
+ def description(description)
20
+ set :description, description
21
+ end
22
+
23
+ def csv(file)
24
+ set :file, file
25
+ end
26
+
27
+ def endpoint(_method)
28
+ return 'contact_lists' if @args[:id].nil?
29
+ id = @args[:id]
30
+ @args.delete :id
31
+ return "contact_lists/#{id}/contacts" unless @args[:file].nil?
32
+ "contact_lists/#{id}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,69 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The dids/search endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_dids_search
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class DidSearch < Base
11
+ def for_country(iso_code)
12
+ set :country, iso_code
13
+ end
14
+
15
+ def toll_free
16
+ type 'toll_free'
17
+ end
18
+
19
+ def local
20
+ type 'local'
21
+ end
22
+
23
+ def national
24
+ type 'national'
25
+ end
26
+
27
+ def mobile
28
+ type 'mobile'
29
+ end
30
+
31
+ def page(page)
32
+ set :page, page
33
+ end
34
+
35
+ def starts_with(pattern)
36
+ with_pattern 'starts_with', pattern
37
+ end
38
+
39
+ def ends_with(pattern)
40
+ with_pattern 'ends_with', pattern
41
+ end
42
+
43
+ def contains(pattern)
44
+ with_pattern 'anywhere', pattern
45
+ end
46
+
47
+ def body(_method)
48
+ ''
49
+ end
50
+
51
+ def endpoint(_method)
52
+ qs = URI.encode_www_form @args
53
+ "dids/search?#{qs}"
54
+ end
55
+
56
+ private
57
+
58
+ def type(type)
59
+ set :type, type
60
+ end
61
+
62
+ def with_pattern(type, pattern)
63
+ set :where_pattern, type
64
+ set :pattern, pattern
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,24 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The me/email_verify endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_email_verify
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class EmailVerify < Base
11
+ def with_nonce(nonce)
12
+ set :nonce, nonce
13
+ end
14
+
15
+ def endpoint(_method)
16
+ return 'me/email_verify' if @args[:nonce].nil?
17
+ nonce = @args[:nonce]
18
+ @args.delete :nonce
19
+ "me/email_verify/#{nonce}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The jobs endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_jobs
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Jobs < Base
11
+ def id(id)
12
+ set :id, id
13
+ end
14
+
15
+ def endpoint(_method)
16
+ return 'jobs' if @args[:id].nil?
17
+ id = @args[:id]
18
+ @args.delete :id
19
+ "jobs/#{id}"
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The recharge endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_recharge
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Recharge < Base
11
+ def with_card(card_id)
12
+ set :card_id, card_id
13
+ end
14
+
15
+ def total(plan_id, total)
16
+ set :plan_id, plan_id
17
+ set :total, total
18
+ end
19
+
20
+ def endpoint(_method)
21
+ 'recharge'
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,45 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The sms endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_sms
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Sms < Base
11
+ def id(id)
12
+ set :id, id
13
+ end
14
+
15
+ def to(to)
16
+ set :to, to
17
+ end
18
+
19
+ def from(from)
20
+ set :from, from
21
+ end
22
+
23
+ def use_template(id, variables = {})
24
+ set :template_id, id
25
+ set :variables, variables
26
+ end
27
+
28
+ def text(text)
29
+ set :text, text
30
+ end
31
+
32
+ def client_ref(client_ref)
33
+ set :client_ref, client_ref
34
+ end
35
+
36
+ def endpoint(_method)
37
+ return 'sms' if @args[:id].nil?
38
+ id = @args[:id]
39
+ @args.delete :id
40
+ "sms/#{id}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # An SMS campaign.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_campaigns
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class SmsCampaign < Campaigns
11
+ def use_template(template_id, variables)
12
+ set :template_id, template_id
13
+ set :variables, variables
14
+ end
15
+
16
+ def text(text)
17
+ set :text, text
18
+ end
19
+
20
+ def initialize
21
+ super
22
+ set :type, 'sms'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The templates endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_templates
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Templates < Base
11
+ def id(id)
12
+ set :id, id
13
+ end
14
+
15
+ def name(name)
16
+ set :name, name
17
+ end
18
+
19
+ def description(description)
20
+ set :description, description
21
+ end
22
+
23
+ def text(text)
24
+ set :text, text
25
+ end
26
+
27
+ def endpoint(_method)
28
+ return 'templates' if @args[:id].nil?
29
+ id = @args[:id]
30
+ @args.delete :id
31
+ "templates/#{id}"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module PortaText
2
+ module Command
3
+ module Api
4
+ # The timezones endpoint.
5
+ # https://github.com/PortaText/docs/wiki/REST-API#api_timezones
6
+ #
7
+ # Author:: Marcelo Gornstein (mailto:marcelog@portatext.com)
8
+ # Copyright:: Copyright (c) 2015 PortaText
9
+ # License:: Apache-2.0
10
+ class Timezones < Base
11
+ def endpoint(_method)
12
+ 'timezones'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -8,6 +8,8 @@ module PortaText
8
8
  # Copyright:: Copyright (c) 2015 PortaText
9
9
  # License:: Apache-2.0
10
10
  class Base
11
+ attr_writer :client
12
+
11
13
  def get
12
14
  run :get
13
15
  end
@@ -34,16 +36,17 @@ module PortaText
34
36
  end
35
37
 
36
38
  def content_type(_method)
39
+ return 'text/csv' unless @args[:file].nil?
37
40
  'application/json'
38
41
  end
39
42
 
40
43
  def body(_method)
44
+ return "file:#{@args[:file]}" unless @args[:file].nil?
41
45
  return '' if @args.size.eql? 0
42
46
  @args.to_json
43
47
  end
44
48
 
45
- def initialize(client)
46
- @client = client
49
+ def initialize
47
50
  @args = {}
48
51
  end
49
52
 
data/lib/portatext.rb CHANGED
@@ -1,3 +1,13 @@
1
+ require_relative 'portatext/exception/request_error'
2
+ require_relative 'portatext/exception/server_error'
3
+ require_relative 'portatext/exception/rate_limited'
4
+ require_relative 'portatext/exception/invalid_media'
5
+ require_relative 'portatext/exception/invalid_method'
6
+ require_relative 'portatext/exception/not_found'
7
+ require_relative 'portatext/exception/forbidden'
8
+ require_relative 'portatext/exception/payment_required'
9
+ require_relative 'portatext/exception/invalid_credentials'
10
+ require_relative 'portatext/exception/client_error'
1
11
  require_relative 'portatext/client/base_client'
2
12
  require_relative 'portatext/client/http_client'
3
13
  require_relative 'portatext/command/descriptor'
@@ -9,16 +19,19 @@ require_relative 'portatext/command/api/acl'
9
19
  require_relative 'portatext/command/api/settings'
10
20
  require_relative 'portatext/command/api/did_settings'
11
21
  require_relative 'portatext/command/api/credit_cards'
12
- require_relative 'portatext/exception/request_error'
13
- require_relative 'portatext/exception/server_error'
14
- require_relative 'portatext/exception/rate_limited'
15
- require_relative 'portatext/exception/invalid_media'
16
- require_relative 'portatext/exception/invalid_method'
17
- require_relative 'portatext/exception/not_found'
18
- require_relative 'portatext/exception/forbidden'
19
- require_relative 'portatext/exception/payment_required'
20
- require_relative 'portatext/exception/invalid_credentials'
21
- require_relative 'portatext/exception/client_error'
22
+ require_relative 'portatext/command/api/email_verify'
23
+ require_relative 'portatext/command/api/templates'
24
+ require_relative 'portatext/command/api/sms'
25
+ require_relative 'portatext/command/api/timezones'
26
+ require_relative 'portatext/command/api/cnam'
27
+ require_relative 'portatext/command/api/recharge'
28
+ require_relative 'portatext/command/api/jobs'
29
+ require_relative 'portatext/command/api/contact_lists'
30
+ require_relative 'portatext/command/api/did_search'
31
+ require_relative 'portatext/command/api/blacklist'
32
+ require_relative 'portatext/command/api/campaigns'
33
+ require_relative 'portatext/command/api/sms_campaign'
34
+ require_relative 'portatext/command/api/campaign_lifecycle'
22
35
 
23
36
  # The PortaText namespace.
24
37
  #
data/portatext.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'portatext'
3
- s.version = '0.0.2'
3
+ s.version = '1.0.0.pre'
4
4
  s.summary = 'Official PortaText API ruby client'
5
5
  s.description = 'This is the official PortaText API ruby client'
6
6
  s.authors = ['PortaText']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portatext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - PortaText
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -140,11 +140,24 @@ files:
140
140
  - lib/portatext/client/base_client.rb
141
141
  - lib/portatext/client/http_client.rb
142
142
  - lib/portatext/command/api/acl.rb
143
+ - lib/portatext/command/api/blacklist.rb
144
+ - lib/portatext/command/api/campaign_lifecycle.rb
145
+ - lib/portatext/command/api/campaigns.rb
146
+ - lib/portatext/command/api/cnam.rb
147
+ - lib/portatext/command/api/contact_lists.rb
143
148
  - lib/portatext/command/api/credit_cards.rb
149
+ - lib/portatext/command/api/did_search.rb
144
150
  - lib/portatext/command/api/did_settings.rb
151
+ - lib/portatext/command/api/email_verify.rb
152
+ - lib/portatext/command/api/jobs.rb
145
153
  - lib/portatext/command/api/me.rb
154
+ - lib/portatext/command/api/recharge.rb
146
155
  - lib/portatext/command/api/settings.rb
156
+ - lib/portatext/command/api/sms.rb
157
+ - lib/portatext/command/api/sms_campaign.rb
147
158
  - lib/portatext/command/api/tariffs.rb
159
+ - lib/portatext/command/api/templates.rb
160
+ - lib/portatext/command/api/timezones.rb
148
161
  - lib/portatext/command/base.rb
149
162
  - lib/portatext/command/descriptor.rb
150
163
  - lib/portatext/command/result.rb
@@ -174,9 +187,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
187
  version: '0'
175
188
  required_rubygems_version: !ruby/object:Gem::Requirement
176
189
  requirements:
177
- - - ">="
190
+ - - ">"
178
191
  - !ruby/object:Gem::Version
179
- version: '0'
192
+ version: 1.3.1
180
193
  requirements: []
181
194
  rubyforge_project:
182
195
  rubygems_version: 2.4.8