Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_PATH: "vendor/bundle"
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.0', '3.1', '3.2']
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Run RSpec
run: bundle exec rspec
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Run RuboCop
run: bundle exec rubocop
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Gemfile.lock
*.sublime-*
.DS_Store
pkg
pkg
vendor/bundle
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
AllCops:
NewCops: enable
SuggestExtensions: false

Gemspec/DevelopmentDependencies:
Enabled: false

Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'

Metrics/ClassLength:
Exclude:
- 'lib/zadarma/client.rb'
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

source 'https://rubygems.org'
gemspec
gemspec
124 changes: 92 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Zadarma API
# Zadarma API Ruby Client

A modern, robust, and fully-featured Ruby client for the Zadarma API. This gem has been updated to support the latest Zadarma API, providing a clean and intuitive interface for all available endpoints.

## Installation

Add this line to your application's Gemfile:

gem 'zadarma'
```ruby
gem 'zadarma'
```

And then execute:

Expand All @@ -16,36 +20,92 @@ Or install it yourself as:

## Usage

Zadarma.api_key = "YOUR_API_KEY"
Zadarma.api_secret = "YOUR_API_SECRET"
Zadarma.log_requests = false # default

Zadarma::Client.balance
or

client = Zadarma::Client.new("YOUR_API_KEY", "YOUR_API_SECRET")
client.balance


## Available methods:

* `balance` - user balance
* `price(number)` - call price
* `callback(from, to, params = {})` - request callback
* `sip` - list user’s SIP-numbers
* `set_sip_caller(id, number)` - change of CallerID
* `redirection(params = {})` - get call forwarding status on SIP-numbers
* `set_redirect(id, params)` - enable/disable sip forwarding
* `pbx_internal` - list PBX internal numbers
* `pbx_record(id, status, params = {})` - toggle call recording
* `send_sms(number, message, params = {})` - send sms
* `statistics(date_start, date_end, params = {})` - get stats
* `pbx_statistics(date_start, date_end)` - get PBX stats
First, configure the client with your API key and secret. You can find these in your Zadarma personal account.

```ruby
require 'zadarma'

client = Zadarma::Client.new(api_key: 'YOUR_API_KEY', api_secret: 'YOUR_API_SECRET')
```

Now you can call any of the available API methods:

### Get Your Balance

```ruby
response = client.balance
puts "Your balance is #{response['balance']} #{response['currency']}."
```

### Get Call Price

```ruby
response = client.price(number: '1234567890')
puts "The price to call 1234567890 is #{response['info']['price']} per minute."
```

### Request a Callback

```ruby
response = client.callback(from: 'YOUR_NUMBER', to: 'DESTINATION_NUMBER')
puts "Callback initiated from #{response['from']} to #{response['to']}."
```

### Send an SMS

```ruby
response = client.send_sms(number: 'DESTINATION_NUMBER', message: 'Hello from Zadarma!')
puts "SMS sent. Cost: #{response['cost']} #{response['currency']}."
```

### Get Call Statistics

```ruby
response = client.statistics(start: '2023-01-01', end_date: '2023-01-31')
response['stats'].each do |call|
puts "Call from #{call['from']} to #{call['to']} on #{call['callstart']}."
end
```

## Available Methods

This client is organized into resources, mirroring the Zadarma API structure.

* **Info**
* `balance`: Get your current account balance.
* `price(number:, caller_id: nil)`: Get the price for a call to a specific number.
* **PBX**
* `internal_numbers`: Get a list of your internal PBX numbers.
* `set_call_recording(id:, status:, email: nil, speech_recognition: nil)`: Enable or disable call recording for a PBX extension.
* **Direct Numbers (Virtual Numbers)**
* `direct_numbers`: Get a list of your virtual numbers.
* **Request**
* `callback(from:, to:, sip: nil, predicted: nil)`: Initiate a callback between two numbers.
* **SIP**
* `sips`: Get a list of your SIP numbers.
* `set_sip_caller_id(id:, number:)`: Set the CallerID for a SIP number.
* `redirection(id: nil)`: Get call forwarding information for a SIP number.
* `set_redirection(id:, status:, type: nil, number: nil, condition: nil)`: Set call forwarding for a SIP number.
* **SMS**
* `send_sms(number:, message:, sender: nil)`: Send an SMS message.
* **Statistics**
* `statistics(start:, end_date:, sip: nil, cost_only: nil, type: nil, skip: nil, limit: nil)`: Get overall call statistics.
* `pbx_statistics(start:, end_date:, version: nil, skip: nil, limit: nil, call_type: nil)`: Get PBX call statistics.

## Development & Testing

To work on this gem locally, clone the repository and then run `bundle install` to install the dependencies.

This gem uses RSpec for testing. To run the test suite, simply run:

$ bundle exec rspec

The test suite is configured to use `webmock` to stub out all API requests, so you can run the tests without needing a live Zadarma account or making real API calls.

## Contributing

1. Fork it ( https://github.com/zhekanax/zadarma-ruby/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
1. Fork it ( https://github.com/SamyRai/zadarma-ruby/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
13 changes: 5 additions & 8 deletions lib/zadarma.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
require "active_support"
require "active_support/core_ext"
require "active_support/json"
require "active_support/hash_with_indifferent_access"
# frozen_string_literal: true

require "zadarma/methods.rb"
require "zadarma/client.rb"
require "zadarma/error.rb"
require 'zadarma/version'
require 'zadarma/client'
require 'zadarma/error'

# The Zadarma module contains all the classes and methods for the Zadarma API client.
module Zadarma
mattr_accessor :api_key, :api_secret, :log_requests
end
Loading