onlinesim 1.0.12 → 2.0.0

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.
@@ -1,66 +0,0 @@
1
- require 'faraday'
2
- require 'oj'
3
- require 'onlinesim/error'
4
-
5
- module FaradayOverrides
6
- def initialize *args
7
- options = args.last
8
- options[:ssl] = {verify: false}
9
- # options[:proxy] = "http://127.0.0.1:4034"
10
- super
11
- end
12
- end
13
-
14
- module OnlineSim
15
- class Base
16
- HTTP_OK_CODE = 200
17
-
18
- def initialize(apikey: nil, lang: 'en', dev_id: nil)
19
- @apikey = apikey
20
- @lang = lang
21
- @dev_id = dev_id
22
-
23
- Faraday.ignore_env_proxy = true
24
- Faraday::Connection.prepend FaradayOverrides
25
- end
26
-
27
- private
28
- def client
29
- @_client ||= Faraday.new('https://onlinesim.host') do |client|
30
- client.request :url_encoded
31
- client.adapter Faraday.default_adapter
32
- client.headers['User-agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
33
- end
34
- end
35
-
36
- protected
37
- def _get(endpoint: '', params: {})
38
- params['apikey'] = @apikey
39
- params['lang'] = @lang
40
- params['dev_id'] = @dev_id
41
- if @dev_id
42
- params['dev_id'] = @dev_id
43
- end
44
- resp = client.public_send("get", '/api/' + endpoint + '.php', params)
45
-
46
- parsed_response = Oj.load(resp.body)
47
-
48
- if resp.status == HTTP_OK_CODE
49
- def valid_json?(parsed_response)
50
- puts parsed_response['response']
51
- if parsed_response.key?('response') and parsed_response['response'].to_s != '1'
52
- raise ApiError, parsed_response['response']
53
- end
54
- if parsed_response.key?('response')
55
- parsed_response.delete('response')
56
- end
57
- rescue JSON::ParserError
58
- end
59
- return parsed_response
60
- end
61
-
62
- raise ApiError, "Code: #{resp.status}, response: #{resp.body}"
63
- end
64
-
65
- end
66
- end
data/lib/onlinesim/cli.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'thor'
2
-
3
- module OnlineSim
4
- class CLI < Thor
5
-
6
- end
7
- end
@@ -1,12 +0,0 @@
1
- module OnlineSim
2
- class BaseError < RuntimeError
3
- end
4
-
5
- class ServerError < BaseError
6
- def initialize(msg = 'Server error') super(msg); end
7
- end
8
-
9
- class ApiError < BaseError
10
- def initialize(msg = 'Api error') super(msg); end
11
- end
12
- end
data/onlinesim.gemspec DELETED
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "onlinesim/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'onlinesim'
8
- spec.version = Onlinesim::VERSION
9
- spec.authors = ['s00d']
10
- spec.email = ['support@onlinesim.ru']
11
-
12
- spec.summary = 'onlinesim.ru Ruby API wrapper'
13
- spec.homepage = 'https://github.com/s00d/onlinesim-ruby-api'
14
- spec.license = 'MIT'
15
-
16
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- end
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency 'faraday', '~> 1.0'
22
- spec.add_dependency 'oj', '~> 3.10'
23
- spec.add_dependency 'thor'
24
- spec.add_development_dependency "bundler", "~> 2.2.27"
25
- end
data/tester.rb DELETED
@@ -1,18 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'onlinesim'
5
-
6
- class Tester
7
- def test
8
- driver = OnlineSim::Driver.new(:apikey => 'APIKEY').numbers
9
- tzid = driver.getwithnumber('vkcom')
10
- puts tzid['number']
11
- puts tzid['tzid']
12
- # countries = driver.countries
13
- # puts countries
14
- # puts driver.wait_code(680507)
15
- end
16
- end
17
-
18
- puts Tester.new.test