faxplus_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9cff90ca10e3d920252b321f3aa2fc7efeeece3334b095a52a4c46c5260d5dba
4
+ data.tar.gz: 5c60b71ccacb08b06425dbfa5e4860a506a93b80ee7945d193b01ef3a52c643e
5
+ SHA512:
6
+ metadata.gz: 8cdb47c45c58ab5c4a5a628bc5bbf8033c155b66f044852ee02a5d7c8826143d603aaef4a37dd54a1be027141c868f06a4073f064a88eac0008b484c698771c2
7
+ data.tar.gz: 02fcc04c4e6d676080b464d2bbaa6d1e7826f02111be7aed005a8cd33778eca08e2e463e7509a8a85f40dd9759763fbb71a70c8c16d793d7b80c0fafa263c831
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # FaxPlus
2
+
3
+ Faxplus is a Ruby library for interacting with faxplus APIs.
4
+
5
+ ## Setting things up.
6
+ To start using faxplus, you first need to add it to your Gemfile, with an entry such as this:
7
+
8
+ ```ruby
9
+ gem 'faxplus_ruby'
10
+ ```
11
+
12
+ Afterwards, run `bundle install`
13
+
14
+ Next, you'll need to create a PAT token from faxplus dashboard here is the link [https://apidoc.fax.plus/v3/?shell#option-1-personal-access-tokens-pats
15
+
16
+ ## Accounts.
17
+
18
+ ```ruby
19
+ client = FaxplusApi::Client.new(access_token: ENV['FAXPLUS_PAT_TOKEN'])
20
+ client.account.accounts # List corporate members
21
+ client.account.user(user_id: 'userid') # Get account information
22
+ client.account.update_user(user_id: 'userid') # Modify account information
23
+ client.account.member(member_user_id: 'member_user_id') # Get member details
24
+ client.account.update_member(member_user_id: 'member_user_id') # Modify member details
25
+ ```
26
+
27
+ ## Numbers.
28
+
29
+ ```ruby
30
+ client.number.list(user_id: 'userid') # List phone numbers
31
+ client.number.get(user_id: 'userid', number: 'number') # Get number information
32
+ client.number.update(user_id: 'userid', number: 'number') # Assign number
33
+ client.number.revoke(user_id: 'userid', number: 'number') # Revoke number
34
+ ```
35
+ ## Faxes.
36
+
37
+ ```ruby
38
+ client.fax.list(user_id: 'userid') # List fax records
39
+ client.fax.get(user_id: 'userid', fax_id: 'fax_id') # Get a fax record
40
+ client.fax.update(user_id: 'userid', fax_id: 'fax_id') # Modify fax record
41
+ client.fax.revoke(user_id: 'userid', fax_id: 'fax_id') # Delete a fax
42
+ ```
43
+ ## Files.
44
+
45
+ ```ruby
46
+ client.file.upload(user_id: 'userid') # Upload a file TODO: Need proper params how to send file
47
+ client.file.get(user_id: 'userid', fax_id: 'fax_id') # Download fax file
48
+ client.file.fax_report(user_id: 'userid', fax_id: 'fax_id') # Get fax confirmation report
49
+ ```
50
+ ## Outbox.
51
+
52
+ ```ruby
53
+ client.outbox.list(user_id: 'userid') # List faxes in the outbox
54
+ # TODO: require proper params here
55
+ client.outbox.send(user_id: 'userid') # Send a fax
56
+ client.outbox.get(user_id: 'userid', outbox_fax_id: 'outbox_fax_id') # List outgoing faxes
57
+ client.outbox.update(user_id: 'userid', outbox_fax_id: 'outbox_fax_id') # Delete an outgoing fax
58
+ client.outbox.delete(user_id: 'userid', outbox_fax_id: 'outbox_fax_id') # Modify an outgoing fax
59
+ ```
60
+ ## Webhooks.
61
+
62
+ ```ruby
63
+ client.webhook.list # List user webhooks
64
+ client.webhook.create # Register new webhook
65
+ client.webhook.delete(hook_id: 'hook_id') # Delete webhook
66
+ ```
67
+
68
+ ## Testing
69
+ TODO
70
+
71
+ ## More help
72
+ Please submit an issue via GitHub if you need more help with the faxplus_ruby gem.
@@ -0,0 +1,29 @@
1
+ require_relative "base"
2
+
3
+ module FaxplusApi
4
+ class Account < Base
5
+ def accounts(url: "#{@base_url}/accounts", data: {})
6
+ make_request(url: url, data: data)
7
+ end
8
+
9
+ def user(url: "#{@base_url}/accounts/%{user_id}", user_id:, data: {})
10
+ url = url % {user_id: user_id}
11
+ make_request(url: url, data: data)
12
+ end
13
+
14
+ def update_user(url: "#{@base_url}/accounts/%{user_id}", user_id:, data: {})
15
+ url = url % {user_id: user_id}
16
+ make_request(url: url, data: data, method: 'put')
17
+ end
18
+
19
+ def member(url: "#{@base_url}/accounts/self/member-details/%{member_user_id}", member_user_id:, data: {})
20
+ url = url % {member_user_id: member_user_id}
21
+ make_request(url: url, data: data)
22
+ end
23
+
24
+ def update_member(url: "#{@base_url}/accounts/self/member-details/%{member_user_id}", member_user_id:, data: {})
25
+ url = url % {member_user_id: member_user_id}
26
+ make_request(url: url, data: data, method: 'put')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module FaxplusApi
5
+ class Base
6
+ def initialize(client)
7
+ @client = client
8
+ @access_token = client.access_token
9
+ @base_url = client.base_url
10
+ end
11
+
12
+ def make_request(url: , data: , method: 'get')
13
+ begin
14
+ response = if method == 'post'
15
+ RestClient.post(url, data.to_json, headers)
16
+ elsif method == 'put'
17
+ RestClient.put(url, data.to_json, headers)
18
+ elsif method == 'get'
19
+ RestClient.get(url, headers)
20
+ elsif method == 'delete'
21
+ RestClient.delete(url, headers)
22
+ end
23
+ rescue RestClient::ExceptionWithResponse => e
24
+ return { error: e.response.body }
25
+ end
26
+
27
+ return response.body if response.body.nil?
28
+
29
+ JSON.parse(response.body, symbolize_names: true) rescue response.body
30
+ end
31
+
32
+ private
33
+
34
+ def headers
35
+ {
36
+ 'Content-Type' => 'application/json',
37
+ 'Accept' => 'application/json',
38
+ 'Authorization' => "Bearer #{@access_token}"
39
+ }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ require_relative "account"
2
+ require_relative "file"
3
+ require_relative "fax"
4
+ require_relative "outbox"
5
+ require_relative "number"
6
+ require_relative "webhook"
7
+
8
+ BASE_URL = "https://restapi.fax.plus/v3"
9
+
10
+ module FaxplusApi
11
+ class Client
12
+
13
+ attr_reader :access_token, :base_url
14
+
15
+ def initialize(access_token: ENV['FAXPLUS_PAT_TOKEN'])
16
+ @access_token = access_token
17
+ @base_url = BASE_URL
18
+ end
19
+
20
+ def file(params = {})
21
+ @file ||= File.new(self)
22
+ end
23
+
24
+ def account(params = {})
25
+ @account ||= Account.new(self)
26
+ end
27
+
28
+ def fax(params = {})
29
+ @fax ||= Fax.new(self)
30
+ end
31
+
32
+ def number(params = {})
33
+ @number ||= Number.new(self)
34
+ end
35
+
36
+ def outbox(params = {})
37
+ @outbox ||= Outbox.new(self)
38
+ end
39
+
40
+ def webhook(params = {})
41
+ @webhook ||= Webhook.new(self)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "base"
2
+
3
+ module FaxplusApi
4
+ class Fax < Base
5
+ def list(url: "#{@base_url}/accounts/%{user_id}/faxes", user_id:, data: {})
6
+ url = url % {user_id: user_id}
7
+ make_request(url: url, data: data)
8
+ end
9
+
10
+ def get(url: "#{@base_url}/accounts/%{user_id}/faxes/%{fax_id}", fax_id:, user_id:, data: {})
11
+ url = url % {user_id: user_id, fax_id: fax_id}
12
+ make_request(url: url, data: data)
13
+ end
14
+
15
+ def update(url: "#{@base_url}/accounts/%{user_id}/faxes/%{fax_id}", fax_id:, user_id:, data: {})
16
+ url = url % {user_id: user_id, fax_id: fax_id}
17
+ make_request(url: url, data: data, method: 'put')
18
+ end
19
+
20
+ def delete(url: "#{@base_url}/accounts/%{user_id}/faxes/%{fax_id}", fax_id:, user_id:, data: {})
21
+ url = url % {user_id: user_id, fax_id: fax_id}
22
+ make_request(url: url, data: data, method: 'delete')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "base"
2
+
3
+ module FaxplusApi
4
+ class File < Base
5
+ def upload(url: "#{@base_url}/accounts/%{user_id}/files", user_id:, data: {})
6
+ url = url % {user_id: user_id}
7
+ make_request(url: url, data: data, method: 'post')
8
+ end
9
+
10
+ def get(url: "#{@base_url}/accounts/%{user_id}/files/%{fax_id}", user_id:, fax_id:, data: {})
11
+ url = url % {user_id: user_id, fax_id: fax_id}
12
+ make_request(url: url, data: data)
13
+ end
14
+
15
+ def fax_report(url: "#{@base_url}/accounts/%{user_id}/report/%{fax_id}", user_id:, fax_id:, data: {})
16
+ url = url % {user_id: user_id, fax_id: fax_id}
17
+ make_request(url: url, data: data)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "base"
2
+
3
+ module FaxplusApi
4
+ class Number < Base
5
+ def list(url: "#{@base_url}/accounts/%{user_id}/numbers", user_id:, data: {})
6
+ url = url % {user_id: user_id}
7
+ make_request(url: url, data: data)
8
+ end
9
+
10
+ def get(url: "#{@base_url}/accounts/%{user_id}/numbers/%{number}", user_id:, number:, data: {})
11
+ url = url % {user_id: user_id, number: number}
12
+ make_request(url: url, data: data)
13
+ end
14
+
15
+ def update(url: "#{@base_url}/accounts/%{user_id}/numbers/%{number}", user_id:, number:, data: {})
16
+ url = url % {user_id: user_id, number: number}
17
+ make_request(url: url, data: data, method: 'put')
18
+ end
19
+
20
+ def revoke(url: "#{@base_url}/accounts/%{user_id}/numbers/%{number}", user_id:, number:, data: {})
21
+ url = url % {user_id: user_id, number: number}
22
+ make_request(url: url, data: data, method: 'delete')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "base"
2
+
3
+ module FaxplusApi
4
+ class Outbox < Base
5
+ def list(url: "#{@base_url}/accounts/%{user_id}/outbox", user_id:, data: {})
6
+ url = url % {user_id: user_id}
7
+ make_request(url: url, data: data)
8
+ end
9
+
10
+ def send(url: "#{@base_url}/accounts/%{user_id}/outbox", user_id:, data: {})
11
+ url = url % {user_id: user_id, fax_id: fax_id}
12
+ make_request(url: url, data: data, method: 'post')
13
+ end
14
+
15
+ def get(url: "#{@base_url}/accounts/%{user_id}/outbox/%{outbox_fax_id}", outbox_fax_id:, user_id:, data: {})
16
+ url = url % {user_id: user_id, outbox_fax_id: outbox_fax_id}
17
+ make_request(url: url, data: data)
18
+ end
19
+
20
+ def update(url: "#{@base_url}/accounts/%{user_id}/outbox/%{outbox_fax_id}", outbox_fax_id:, user_id:, data: {})
21
+ url = url % {user_id: user_id, outbox_fax_id: outbox_fax_id}
22
+ make_request(url: url, data: data, method: 'put')
23
+ end
24
+
25
+ def delete(url: "#{@base_url}/accounts/%{user_id}/outbox/%{outbox_fax_id}", outbox_fax_id:, user_id:, data: {})
26
+ url = url % {user_id: user_id, outbox_fax_id: outbox_fax_id}
27
+ make_request(url: url, data: data, method: 'delete')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module FaxplusApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "base"
2
+
3
+ module FaxplusApi
4
+ class Webhook < Base
5
+ def list(url: "#{@base_url}/hooks", data: {})
6
+ make_request(url: url, data: data)
7
+ end
8
+
9
+ def create(url: "#{@base_url}/hooks", data: {})
10
+ make_request(url: url, data: data, method: 'post')
11
+ end
12
+
13
+ def delete(url: "#{@base_url}/hooks/%{hook_id}", hook_id:, data: {})
14
+ url = url % {hook_id: hook_id}
15
+ make_request(url: url, data: data, method: 'delete')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "faxplus_api/version"
2
+ require_relative "faxplus_api/client"
3
+ require_relative "faxplus_api/base"
4
+ require_relative "faxplus_api/account"
5
+ require_relative "faxplus_api/file"
6
+ require_relative "faxplus_api/fax"
7
+ require_relative "faxplus_api/outbox"
8
+ require_relative "faxplus_api/number"
9
+ require_relative "faxplus_api/webhook"
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faxplus_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dilkhush Soni
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ description:
56
+ email:
57
+ - dilkhushsoni2010@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - lib/faxplus_api.rb
64
+ - lib/faxplus_api/account.rb
65
+ - lib/faxplus_api/base.rb
66
+ - lib/faxplus_api/client.rb
67
+ - lib/faxplus_api/fax.rb
68
+ - lib/faxplus_api/file.rb
69
+ - lib/faxplus_api/number.rb
70
+ - lib/faxplus_api/outbox.rb
71
+ - lib/faxplus_api/version.rb
72
+ - lib/faxplus_api/webhook.rb
73
+ homepage: https://github.com/dilkhush/faxplus-ruby
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.7.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.1.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A simple wrapper around ifaxapp's API
96
+ test_files: []