hipcall 1.0.0

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: 0714276b651ff95a6fde2b7c36c85acc5e6170065e4a8d07e52712543a35ae1c
4
+ data.tar.gz: 80f7fb286ead1667610808cdccb697422976dc54b90fd33481aed108d1c4c829
5
+ SHA512:
6
+ metadata.gz: 343a8bfbf09322c45e6bd0b3f4149032b3039a01d95a3aef55fdd875be8e6b034ebcf51c511a42d7f4b2ad1413dfe63240bad0f93100c43592e3f662c6693e84
7
+ data.tar.gz: b2d507c8517047aea14069905e5ad57aa11ed8bc5f95e93e0f7182a65b9f439388110c8a722133716c54dadc68c6f0d70bc85a03a07a1ebec075e42b4e8c9e6c
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## v1.0.0
4
+
5
+ ### Features
6
+
7
+ - Add cdr resource
8
+ - Add number resource
9
+ - Add task resource
10
+ - Add user resource
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM ruby:3.0
2
+
3
+ # throw errors if Gemfile has been modified since Gemfile.lock
4
+ RUN bundle config --global frozen 1
5
+
6
+ WORKDIR /usr/src/hipcall-sdk
7
+
8
+ COPY . .
9
+
10
+ RUN bundle install
11
+
12
+ CMD bash
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in hipcall.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "minitest", ">= 5.0.5"
10
+ gem "standard"
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hipcall (1.0.0)
5
+ faraday (~> 1.10)
6
+ faraday_middleware (~> 1.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ faraday (1.10.0)
13
+ faraday-em_http (~> 1.0)
14
+ faraday-em_synchrony (~> 1.0)
15
+ faraday-excon (~> 1.1)
16
+ faraday-httpclient (~> 1.0)
17
+ faraday-multipart (~> 1.0)
18
+ faraday-net_http (~> 1.0)
19
+ faraday-net_http_persistent (~> 1.0)
20
+ faraday-patron (~> 1.0)
21
+ faraday-rack (~> 1.0)
22
+ faraday-retry (~> 1.0)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-em_http (1.0.0)
25
+ faraday-em_synchrony (1.0.0)
26
+ faraday-excon (1.1.0)
27
+ faraday-httpclient (1.0.1)
28
+ faraday-multipart (1.0.4)
29
+ multipart-post (~> 2)
30
+ faraday-net_http (1.0.1)
31
+ faraday-net_http_persistent (1.2.0)
32
+ faraday-patron (1.0.0)
33
+ faraday-rack (1.0.0)
34
+ faraday-retry (1.0.3)
35
+ faraday_middleware (1.2.0)
36
+ faraday (~> 1.0)
37
+ minitest (5.16.2)
38
+ multipart-post (2.2.3)
39
+ parallel (1.22.1)
40
+ parser (3.1.2.0)
41
+ ast (~> 2.4.1)
42
+ rainbow (3.1.1)
43
+ rake (13.0.6)
44
+ regexp_parser (2.5.0)
45
+ rexml (3.2.5)
46
+ rubocop (1.29.1)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.1.0.0)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.17.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.18.0)
56
+ parser (>= 3.1.1.0)
57
+ rubocop-performance (1.13.3)
58
+ rubocop (>= 1.7.0, < 2.0)
59
+ rubocop-ast (>= 0.4.0)
60
+ ruby-progressbar (1.11.0)
61
+ ruby2_keywords (0.0.5)
62
+ standard (1.12.1)
63
+ rubocop (= 1.29.1)
64
+ rubocop-performance (= 1.13.3)
65
+ unicode-display_width (2.2.0)
66
+
67
+ PLATFORMS
68
+ x86_64-linux
69
+
70
+ DEPENDENCIES
71
+ hipcall!
72
+ minitest (>= 5.0.5)
73
+ rake (~> 13.0)
74
+ standard
75
+
76
+ BUNDLED WITH
77
+ 2.2.33
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Hipcall
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/hipcall`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hipcall'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hipcall
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ hipcall = Hipcall::Client.new(api_key: "YOUR_TOKEN_IS_HERE", version: "v20211124", base_url: "https://app.hipcall.com.tr/api/")
25
+ ```
26
+
27
+ ### Cdr resource
28
+
29
+ ```ruby
30
+ # List
31
+ cdrs = hipcall.cdrs.list
32
+
33
+ # Retrieve
34
+ year = 2022
35
+ mounth = 07
36
+ day = 07
37
+ cdr_uuid = "caedfd1b-25ec-447e-ad87-3b7eb3d358ea"
38
+ cdr = hipcall.cdrs.retrieve(year: year, mounth: mounth, day: day, cdr_uuid: cdr_uuid)
39
+ ```
40
+
41
+ ### Number resource
42
+
43
+ ```ruby
44
+ # List
45
+ numbers = hipcall.numbers.list
46
+
47
+ # Retrieve
48
+ number = hipcall.numbers.retrieve(number_id: 1)
49
+ ```
50
+
51
+ ### Task resource
52
+
53
+ ```ruby
54
+ # List
55
+ tasks = hipcall.tasks.list
56
+
57
+ # Retrieve
58
+ task = hipcall.tasks.retrieve(task_id: 1)
59
+
60
+ # Create
61
+ new_task = hipcall.tasks.create(name: 'Lets email the contact')
62
+ ```
63
+
64
+ ### User resource
65
+
66
+ ```ruby
67
+ # List
68
+ users = hipcall.users.list
69
+
70
+ # Retrieve
71
+ user = hipcall.users.retrieve(user_id: 1)
72
+ ```
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hipcall/ruby-sdk .
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
11
+
12
+ task :console do
13
+ exec "irb -I lib -r hipcall.rb"
14
+ end
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "hipcall"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ client = Hipcall::Client.new(api_key: ENV["HIPCALL_API_KEY"])
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/hipcall.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hipcall/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hipcall"
7
+ spec.version = Hipcall::VERSION
8
+ spec.authors = ["Hipcall Development Team", "Onur Ozgur OZKAN"]
9
+ spec.email = ["hello@hipcall.com"]
10
+
11
+ spec.summary = "Hipcall's Ruby SDK"
12
+ spec.homepage = "https://www.hipcall.com"
13
+ spec.required_ruby_version = ">= 2.6.0"
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/hipcall/ruby-sdk"
19
+ spec.metadata["changelog_uri"] = "https://github.com/hipcall/ruby-sdk/blob/master/CHANGELOG.md"
20
+ spec.licenses = "MIT"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ spec.add_dependency "faraday", "~> 1.10"
35
+ spec.add_dependency "faraday_middleware", "~> 1.2"
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,41 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ module Hipcall
5
+ class Client
6
+ attr_reader :api_key, :version, :base_url, :adapter
7
+
8
+ def initialize(api_key:, version: "v20211124", base_url: "https://app.hipcall.com/api/", adapter: Faraday.default_adapter, stubs: nil)
9
+ @api_key = api_key
10
+ @version = version
11
+ @base_url = base_url
12
+ @adapter = adapter
13
+ @stubs = stubs
14
+ end
15
+
16
+ def cdrs
17
+ CdrResource.new(self)
18
+ end
19
+
20
+ def numbers
21
+ NumberResource.new(self)
22
+ end
23
+
24
+ def tasks
25
+ TaskResource.new(self)
26
+ end
27
+
28
+ def users
29
+ UserResource.new(self)
30
+ end
31
+
32
+ def connection
33
+ @connection ||= Faraday.new (base_url + version) do |connection|
34
+ connection.request :authorization, :Bearer, api_key
35
+ connection.request :json, :accept => 'application/json'
36
+ connection.response :json, content_type: "application/json"
37
+ connection.adapter adapter, @stubs
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ module Hipcall
2
+ class Collection
3
+ attr_reader :data, :links, :meta
4
+
5
+ def self.from_response(response, key:, type:)
6
+ body = response.body
7
+ new(
8
+ data: body[key].map { |attrs| type.new(attrs) },
9
+ links: body["links"],
10
+ meta: body["meta"],
11
+ )
12
+ end
13
+
14
+ def initialize(data:, links:, meta:)
15
+ @data = data
16
+ @links = links
17
+ @meta = meta
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module Hipcall
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require "ostruct"
2
+
3
+ module Hipcall
4
+ class Object < OpenStruct
5
+ def initialize(attributes)
6
+ super to_ostruct(attributes)
7
+ end
8
+
9
+ def to_ostruct(obj)
10
+ if obj.is_a?(Hash)
11
+ OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
12
+ elsif obj.is_a?(Array)
13
+ obj.map { |o| to_ostruct(o) }
14
+ else # Assumed to be a primitive value
15
+ obj
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ module Hipcall
2
+ class Cdr < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Hipcall
2
+ class Number < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Hipcall
2
+ class Task < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Hipcall
2
+ class User < Object
3
+ end
4
+ end
@@ -0,0 +1,53 @@
1
+ module Hipcall
2
+ class Resource
3
+ attr_reader :client
4
+
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def get_request(url, params: {}, headers: {})
12
+ handle_response client.connection.get(url, params, headers)
13
+ end
14
+
15
+ def post_request(url, body:, headers: {})
16
+ handle_response client.connection.post(url, body, headers)
17
+ end
18
+
19
+ def patch_request(url, body:, headers: {})
20
+ handle_response client.connection.patch(url, body, headers)
21
+ end
22
+
23
+ def put_request(url, body:, headers: {})
24
+ handle_response client.connection.put(url, body, headers)
25
+ end
26
+
27
+ def delete_request(url, params: {}, headers: {})
28
+ handle_response client.connection.delete(url, params, headers)
29
+ end
30
+
31
+ def handle_response(response)
32
+ message = response.body["errors"]
33
+ case response.status
34
+ when 400
35
+ raise Error, message
36
+ when 401
37
+ raise Error, message
38
+ when 403
39
+ raise Error, message
40
+ when 404
41
+ raise Error, message
42
+ when 419
43
+ raise Error, message
44
+ when 429
45
+ raise Error, message
46
+ when 500
47
+ raise Error, message
48
+ end
49
+
50
+ response
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ module Hipcall
2
+ class CdrResource < Resource
3
+ def list(**params)
4
+ response = get_request("cdrs", params: params)
5
+ Collection.from_response(response, key: "data", type: Cdr)
6
+ end
7
+
8
+ def retrieve(year:, mounth:, day:, cdr_uuid:)
9
+ Cdr.new get_request("cdrs/#{year}/#{mounth}/#{day}/#{cdr_uuid}").body.dig("data")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Hipcall
2
+ class NumberResource < Resource
3
+ def list(**params)
4
+ response = get_request("numbers", params: params)
5
+ Collection.from_response(response, key: "data", type: Number)
6
+ end
7
+
8
+ def retrieve(number_id:)
9
+ Number.new get_request("numbers/#{number_id}").body.dig("data")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module Hipcall
2
+ class TaskResource < Resource
3
+ def list(**params)
4
+ response = get_request("tasks", params: params)
5
+ Collection.from_response(response, key: "data", type: Task)
6
+ end
7
+
8
+ def retrieve(task_id:)
9
+ Task.new get_request("tasks/#{task_id}").body.dig("data")
10
+ end
11
+
12
+ def create(**attributes)
13
+ Task.new post_request("tasks", body: attributes).body.dig("data")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Hipcall
2
+ class UserResource < Resource
3
+ def list(**params)
4
+ response = get_request("users", params: params)
5
+ Collection.from_response(response, key: "data", type: User)
6
+ end
7
+
8
+ def retrieve(user_id:)
9
+ User.new get_request("users/#{user_id}").body.dig("data")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hipcall
4
+ VERSION = "1.0.0"
5
+ end
data/lib/hipcall.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "hipcall/version"
4
+
5
+ module Hipcall
6
+ autoload :Client, "hipcall/client"
7
+ autoload :Collection, "hipcall/collection"
8
+ autoload :Error, "hipcall/error"
9
+ autoload :Object, "hipcall/object"
10
+ autoload :Resource, "hipcall/resource"
11
+
12
+
13
+ autoload :Cdr, "hipcall/objects/cdr"
14
+ autoload :Number, "hipcall/objects/number"
15
+ autoload :Task, "hipcall/objects/task"
16
+ autoload :User, "hipcall/objects/user"
17
+
18
+ autoload :CdrResource, "hipcall/resources/cdrs"
19
+ autoload :NumberResource, "hipcall/resources/numbers"
20
+ autoload :TaskResource, "hipcall/resources/tasks"
21
+ autoload :UserResource, "hipcall/resources/users"
22
+ end
@@ -0,0 +1,4 @@
1
+ module Hipcall
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hipcall
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hipcall Development Team
8
+ - Onur Ozgur OZKAN
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2022-07-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.2'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.2'
42
+ description:
43
+ email:
44
+ - hello@hipcall.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - Dockerfile
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - hipcall.gemspec
58
+ - lib/hipcall.rb
59
+ - lib/hipcall/client.rb
60
+ - lib/hipcall/collection.rb
61
+ - lib/hipcall/error.rb
62
+ - lib/hipcall/object.rb
63
+ - lib/hipcall/objects/cdr.rb
64
+ - lib/hipcall/objects/number.rb
65
+ - lib/hipcall/objects/task.rb
66
+ - lib/hipcall/objects/user.rb
67
+ - lib/hipcall/resource.rb
68
+ - lib/hipcall/resources/cdrs.rb
69
+ - lib/hipcall/resources/numbers.rb
70
+ - lib/hipcall/resources/tasks.rb
71
+ - lib/hipcall/resources/users.rb
72
+ - lib/hipcall/version.rb
73
+ - sig/hipcall/hipcall.rbs
74
+ homepage: https://www.hipcall.com
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://www.hipcall.com
79
+ source_code_uri: https://github.com/hipcall/ruby-sdk
80
+ changelog_uri: https://github.com/hipcall/ruby-sdk/blob/master/CHANGELOG.md
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.2.33
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Hipcall's Ruby SDK
100
+ test_files: []