luminati-ruby 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 29c41473dacef780c406525ebdf44c9fd12e369969f30d38c088fb1e9d9aa6b7
4
+ data.tar.gz: 5eaf07fa086cbc8d332cdbec57e60358152afab98925f93b72531b2ff48d5b89
5
+ SHA512:
6
+ metadata.gz: 2177ca10a6ae3db31f46f5c624302e9a9d4af3baccf0cd380c9c237d5c3c58a5df76fc3994dc825b7161048b149fe115ff7ef91d0bfd5432d67db255c4632d44
7
+ data.tar.gz: 2806323cc6eb8fa966178c225302e097be41a7d056335cbd4dabd73a7d825eade1df7557dcd46b8347f8e325225d35d68816c458b72c37dc78051a341408f7d3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 doublemarket
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # luminati-ruby
2
+
3
+ A Ruby interface to the [Luminati API](https://luminati.io/doc/api).
4
+
5
+ **Caution: This gem currently supports only selected endpoints of the existing API.** Those are missing:
6
+
7
+ - Some endpoints of [the Account management API](https://luminati.io/doc/api#account_api).
8
+ - [Proxy Manager API](https://luminati.io/doc/api#lpm_endpoints)
9
+
10
+ Check out the [documentation](https://rubydoc.info/gems/luminati-ruby) for which ones are supported.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'luminati-ruby'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```
23
+ $ bundle install
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```
29
+ $ gem install luminati-ruby
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Get `Luminati::Client` by calling `Luminati::Client.new` with an API token. You can get your API token via https://luminati.io/cp/setting.
35
+
36
+ ```
37
+ client = Luminati::Client.new("your api token")
38
+ ```
39
+
40
+ and call any methods you want to use:
41
+
42
+ ```
43
+ client.active_zones
44
+ => [{"name"=>"testzone01", "type"=>"dc"}]
45
+ ```
46
+
47
+ Also refer to the documentation https://rubydoc.info/gems/luminati-ruby
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/doublemarket/luminati-ruby.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luminati
4
+ class Client
5
+ module Customer
6
+ # Returns the bandwidth stats for all your zones.
7
+ # @see https://luminati.io/doc/api#stats_api_bw_cust
8
+ # @param from [String] This should be in the format `2018-07-01T00:00:00`.
9
+ # @param to [String] This should be in the format `2018-07-02T00:00:00`.
10
+ # @return [Hash]
11
+ def customer_bandwidth_stats(from = nil, to = nil)
12
+ parameters = "details=1"
13
+ parameters << "&from=#{from}" if from
14
+ parameters << "&to=#{to}" if to
15
+ request(:get, "/api/customer/bw?#{parameters}")
16
+ end
17
+
18
+ # Returns the total balance of your account.
19
+ # @see https://luminati.io/doc/api#account_api_balance
20
+ # @return [Hash]
21
+ def customer_balance
22
+ request(:get, "/api/customer/balance")
23
+ end
24
+ end
25
+ end
26
+ end
File without changes
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luminati
4
+ class Client
5
+ module Zone
6
+ module Ips
7
+ # Returns datacenter IPs for a given zone.
8
+ # @see https://luminati.io/doc/api#account_api_zone_datacenter_ips
9
+ # @param zone_name [String]
10
+ # @param ip_per_country [Boolean] `true` when you want to get a total amount of IPs per country
11
+ # @return [Hash]
12
+ def zone_ips(zone_name, ip_per_country = false)
13
+ parameters = "zone=#{zone_name}"
14
+ parameters << "&ip_per_country" if ip_per_country
15
+ request(:get, "/api/zone/ips?#{parameters}")
16
+ end
17
+
18
+ # Returns zones and IPs with connectivity issues.
19
+ # @see https://luminati.io/doc/api#allocated_unavailable_ips
20
+ # @return [Hash] When there's no zones that has issues, this should be `{}`.
21
+ def unavailable_zones_ips
22
+ request(:get, "/api/zone/ips/unavailable")
23
+ end
24
+
25
+ # Add IPs to a given zone
26
+ # @see https://luminati.io/doc/api#account_api_add_ips
27
+ # @param ip_info [Hash]
28
+ # @return [Hash] Added IPs information
29
+ def add_ips(ip_info)
30
+ data = ip_info
31
+ request(:post, "/api/zone/ips", Oj.dump(data, mode: :compat))
32
+ end
33
+
34
+ # Remove Ips from a given zone
35
+ # @see https://luminati.io/doc/api#account_api_remove_ips
36
+ # @param zone_name [String]
37
+ # @param ips [Array] An array of IPs
38
+ # @return [Hash]
39
+ def remove_ips(zone_name, ips)
40
+ data = {}
41
+ data["zone"] = zone_name
42
+ data["ips"] = ips
43
+ request(:delete, "/api/zone/ips", Oj.dump(data, mode: :compat))
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luminati
4
+ class Client
5
+ module Zone
6
+ # Returns the bandwidth stats for a given zone
7
+ # @see https://luminati.io/doc/api#stats_api_bw_zone
8
+ # @param zone_name [String]
9
+ # @param from [String] This should be in the format `2018-07-01T00:00:00`.
10
+ # @param to [String] This should be in the format `2018-07-02T00:00:00`.
11
+ # @return [Hash]
12
+ def zone_bandwidth_stats(zone_name, from = nil, to = nil)
13
+ parameters = "zone=#{zone_name}&details=1"
14
+ parameters << "&from=#{from}" if from
15
+ parameters << "&to=#{to}" if to
16
+ request(:get, "/api/zone/bw?#{parameters}")
17
+ end
18
+
19
+ # Returns the cost and the bandwidth stats for a given zone
20
+ # @see https://luminati.io/doc/api#stats_api_cost_zone
21
+ # @param zone_name [String]
22
+ # @param from [String] This should be in the format `2018-07-01T00:00:00`.
23
+ # @param to [String] This should be in the format `2018-07-02T00:00:00`.
24
+ # @return [Hash]
25
+ def zone_cost_stats(zone_name, from = nil, to = nil)
26
+ parameters = "zone=#{zone_name}"
27
+ parameters << "&from=#{from}" if from
28
+ parameters << "&to=#{to}" if to
29
+ request(:get, "/api/zone/cost?#{parameters}")
30
+ end
31
+
32
+ # Returns the number of available IPs
33
+ # @see https://luminati.io/doc/api#account_api_count_available_ips
34
+ # @param zone_name [String]
35
+ # @param plan [Hash]
36
+ # @return [Hash]
37
+ def zone_available_ip_count(zone_name, plan = nil)
38
+ parameters = "zone=#{zone_name}"
39
+ parameters << "&plan=#{Oj.dump(plan, mode: :compat)}" if plan
40
+ request(:get, "/api/zone/count_available_ips?#{parameters}")
41
+ end
42
+
43
+ # Returns recent IPs attempting to use a given zone
44
+ # @see https://luminati.io/doc/api#ip_mgmnt_api_ip_attempt
45
+ # @param zone_names [String] `*` or zone names separated with `,`
46
+ # @return [Hash]
47
+ def zone_recent_ips(zone_names)
48
+ parameters = "zones=#{zone_names}"
49
+ request(:get, "/api/zone/recent_ips?#{parameters}")
50
+ end
51
+
52
+ # Returns avaialble IPs in a given zone and a given country
53
+ # @see https://luminati.io/doc/api#ip_mgmnt_ips_country_dc
54
+ # @param zone_name [String]
55
+ # @param country_code [String] A country code like `US`.
56
+ # @param expand [Boolean] `true` when you want expanded IPs
57
+ # @return [Hash]
58
+ def zone_available_ips(zone_name, country_code = nil, expand = false)
59
+ parameters = "zone=#{zone_name}"
60
+ parameters << "&country=#{country_code}" if country_code
61
+ parameters << "&expand=1" if expand
62
+ request(:get, "/api/zone/route_ips?#{parameters}")
63
+ end
64
+
65
+ # Returns available VIPs in a given zone
66
+ # @see https://luminati.io/doc/api#ip_mgmnt_gips
67
+ # @param zone_name [String]
68
+ # @return [Hash]
69
+ def zone_available_vips(zone_name)
70
+ parameters = "zone=#{zone_name}"
71
+ request(:get, "/api/zone/route_vips?#{parameters}")
72
+ end
73
+
74
+ # Returns the information of a given zone
75
+ # @see https://luminati.io/doc/api#account_api_get_zone
76
+ # @param zone_name [String]
77
+ # @return [Hash]
78
+ def zone_info(zone_name)
79
+ parameters = "zone=#{zone_name}"
80
+ request(:get, "/api/zone?#{parameters}")
81
+ end
82
+
83
+ # Adds a zone
84
+ # @see https://luminati.io/doc/api#account_api_add_zone
85
+ # @param zone_info [Hash]
86
+ # @param plan_info [Hash]
87
+ # @return [String] The official API documentation says it returns the information of the added zone but currently it returns just `OK`.
88
+ def add_zone(zone_info, plan_info)
89
+ data = {}
90
+ data["zone"] = zone_info unless zone_info.empty?
91
+ data["plan"] = plan_info unless plan_info.empty?
92
+ request(:post, "/api/zone", Oj.dump(data, mode: :compat))
93
+ end
94
+
95
+ # Remove a zone
96
+ # @see https://luminati.io/doc/api#account_api_remove_zone
97
+ # @param zone_name [String]
98
+ # @return [String] The official API documentation says it returns the information of the added zone but currently it returns just `OK`.
99
+ def remove_zone(zone_name)
100
+ data = {}
101
+ data["zone"] = zone_name
102
+ request(:delete, "/api/zone", Oj.dump(data, mode: :compat))
103
+ end
104
+
105
+ # Returns passwords of a given zone
106
+ # @see https://luminati.io/doc/api#account_api_zone_passwords
107
+ # @param zone_name [String]
108
+ # @returns [Hash]
109
+ def zone_passwords(zone_name)
110
+ parameters = "zone=#{zone_name}"
111
+ request(:get, "/api/zone/passwords?#{parameters}")
112
+ end
113
+
114
+ # Returns permissions of a given zone
115
+ # @see https://luminati.io/doc/api#account_api_zone_perms
116
+ # @param zone_name [String]
117
+ # @returns [Hash]
118
+ def zone_permissions(zone_name)
119
+ parameters = "zone=#{zone_name}"
120
+ request(:get, "/api/zone/permissions?#{parameters}")
121
+ end
122
+
123
+ # Returns the status of a given zone
124
+ # @see https://luminati.io/doc/api#account_api_zone_status
125
+ # @param zone_name [String]
126
+ # @returns [Hash]
127
+ def zone_status(zone_name)
128
+ parameters = "zone=#{zone_name}"
129
+ request(:get, "/api/zone/status?#{parameters}")
130
+ end
131
+
132
+ # Returns active zones
133
+ # @see https://luminati.io/doc/api#account_api_get_active_zones
134
+ # @returns [Hash]
135
+ def active_zones
136
+ request(:get, "/api/zone/get_active_zones")
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "luminati/client/zone"
4
+ require "luminati/client/zone/ips"
5
+ require "luminati/client/customer"
6
+
7
+ module Luminati
8
+ class Client
9
+ include Luminati::Client::Zone
10
+ include Luminati::Client::Zone::Ips
11
+ include Luminati::Client::Customer
12
+
13
+ API_URL = "https://luminati.io"
14
+
15
+ attr_accessor :api_token
16
+
17
+ # Initializes a new Client object.
18
+ # @param api_token [String]
19
+ # @return [Luminati::Client]
20
+ def initialize(api_token = nil)
21
+ instance_variable_set("@api_token", api_token) if api_token
22
+ end
23
+
24
+ # Returns the current service status for a given network type
25
+ # @see https://luminati.io/doc/api#account_api_stat
26
+ # @param network_type [Symbol] A network type, one of `:all`, `:res`, `:dc`, `:mobile`.
27
+ # @return [Hash]
28
+ def network_status(network_type = :all)
29
+ request(:get, "/api/network_status/#{network_type}")
30
+ end
31
+
32
+ # Returns cities for a given country
33
+ # @see https://luminati.io/doc/api#others_get_cities
34
+ # @param country_code [String] A country code like `US`.
35
+ # @return [Hash]
36
+ def cities(country_code)
37
+ request(:get, "/api/cities?country=#{country_code}")
38
+ end
39
+
40
+ private
41
+
42
+ def conn
43
+ headers = {
44
+ "Content-Type": "application/json"
45
+ }
46
+ headers = headers.merge({ "Authorization": "Bearer #{@api_token}" }) if @api_token
47
+ @conn ||= Faraday.new(
48
+ API_URL,
49
+ request: { timeout: 5 },
50
+ headers: headers
51
+ )
52
+ end
53
+
54
+ def request(method, path, options = nil)
55
+ res = if method == :delete
56
+ conn.delete(path) { |req| req.body = options }
57
+ else
58
+ conn.public_send(method, path, options)
59
+ end
60
+ if res.status == 200
61
+ begin
62
+ Oj.load(res.body)
63
+ rescue Oj::ParseError
64
+ # when the body isn't JSON (e.g. GET /api/zone/route_ips)
65
+ res.body
66
+ end
67
+ else
68
+ { "status_code" => res.status, "status_message" => res.reason_phrase, "response_body" => res.body }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luminati
4
+ VERSION = "0.0.2"
5
+ end
data/lib/luminati.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "oj"
5
+ require_relative "luminati/version"
6
+ require_relative "luminati/client"
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/luminati/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "luminati-ruby"
7
+ spec.version = Luminati::VERSION
8
+ spec.authors = ["doublemarket"]
9
+ spec.email = ["doublemarket@gmail.com"]
10
+
11
+ spec.description = "A Ruby interface to the Luminati API"
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/doublemarket/luminati-ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/doublemarket/luminati-ruby"
19
+ spec.metadata["changelog_uri"] = "https://github.com/doublemarket/luminati-ruby"
20
+
21
+ spec.files = %w[LICENSE.txt README.md luminati-ruby.gemspec] + Dir["lib/**/*.rb"]
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "faraday", "~> 1.0"
25
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: luminati-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - doublemarket
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: A Ruby interface to the Luminati API
28
+ email:
29
+ - doublemarket@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE.txt
35
+ - README.md
36
+ - lib/luminati.rb
37
+ - lib/luminati/client.rb
38
+ - lib/luminati/client/customer.rb
39
+ - lib/luminati/client/proxies.rb
40
+ - lib/luminati/client/zone.rb
41
+ - lib/luminati/client/zone/ips.rb
42
+ - lib/luminati/version.rb
43
+ - luminati-ruby.gemspec
44
+ homepage: https://github.com/doublemarket/luminati-ruby
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/doublemarket/luminati-ruby
49
+ source_code_uri: https://github.com/doublemarket/luminati-ruby
50
+ changelog_uri: https://github.com/doublemarket/luminati-ruby
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.4.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.2.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: A Ruby interface to the Luminati API
70
+ test_files: []