supercast 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/supercast.rb ADDED
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Supercast Ruby bindings
4
+ require 'cgi'
5
+ require 'faraday'
6
+ require 'json'
7
+ require 'logger'
8
+ require 'openssl'
9
+ require 'rbconfig'
10
+ require 'securerandom'
11
+ require 'set'
12
+ require 'socket'
13
+ require 'uri'
14
+
15
+ # Version
16
+ require_relative 'supercast/version'
17
+
18
+ # API operations
19
+ require_relative 'supercast/operations/create'
20
+ require_relative 'supercast/operations/destroy'
21
+ require_relative 'supercast/operations/list'
22
+ require_relative 'supercast/operations/request'
23
+ require_relative 'supercast/operations/save'
24
+
25
+ # API resource support classes
26
+ require_relative 'supercast/errors'
27
+ require_relative 'supercast/client'
28
+ require_relative 'supercast/data_types'
29
+ require_relative 'supercast/util'
30
+ require_relative 'supercast/data_object'
31
+ require_relative 'supercast/response'
32
+ require_relative 'supercast/data_list'
33
+ require_relative 'supercast/resource'
34
+ require_relative 'supercast/singleton'
35
+
36
+ # Named API resources
37
+ require_relative 'supercast/resources'
38
+
39
+ module Supercast
40
+ DEFAULT_CA_BUNDLE_PATH ||= __dir__ + '/data/ca-certificates.crt'
41
+
42
+ @api_base = 'https://supercast.com/api'
43
+ @api_version = 'v1'
44
+
45
+ @log_level = nil
46
+ @logger = nil
47
+
48
+ @proxy = nil
49
+
50
+ @max_network_retries = 0
51
+ @max_network_retry_delay = 2
52
+ @initial_network_retry_delay = 0.5
53
+
54
+ @ca_bundle_path = DEFAULT_CA_BUNDLE_PATH
55
+ @ca_store = nil
56
+ @verify_ssl_certs = true
57
+
58
+ @open_timeout = 30
59
+ @read_timeout = 80
60
+
61
+ class << self
62
+ attr_accessor :api_key, :api_base, :verify_ssl_certs,
63
+ :api_version, :open_timeout, :read_timeout, :proxy
64
+
65
+ attr_reader :max_network_retry_delay, :initial_network_retry_delay
66
+ end
67
+
68
+ # The location of a file containing a bundle of CA certificates. By default
69
+ # the library will use an included bundle that can successfully validate
70
+ # Supercast certificates.
71
+ def self.ca_bundle_path
72
+ @ca_bundle_path
73
+ end
74
+
75
+ def self.ca_bundle_path=(path)
76
+ @ca_bundle_path = path
77
+
78
+ # empty this field so a new store is initialized
79
+ @ca_store = nil
80
+ end
81
+
82
+ # A certificate store initialized from the the bundle in #ca_bundle_path and
83
+ # which is used to validate TLS on every request.
84
+ #
85
+ # This was added to the give the gem "pseudo thread safety" in that it seems
86
+ # when initiating many parallel requests marshaling the certificate store is
87
+ # the most likely point of failure. Any program attempting
88
+ # to leverage this pseudo safety should make a call to this method (i.e.
89
+ # `Supercast.ca_store`) in their initialization code because it marshals lazily
90
+ # and is itself not thread safe.
91
+ def self.ca_store
92
+ @ca_store ||= begin
93
+ store = OpenSSL::X509::Store.new
94
+ store.add_file(ca_bundle_path)
95
+ store
96
+ end
97
+ end
98
+
99
+ # Map to the same values as the standard library's logger
100
+ LEVEL_DEBUG ||= Logger::DEBUG
101
+ LEVEL_ERROR ||= Logger::ERROR
102
+ LEVEL_INFO ||= Logger::INFO
103
+
104
+ # When set prompts the library to log some extra information to $stdout and
105
+ # $stderr about what it's doing. For example, it'll produce information about
106
+ # requests, responses, and errors that are received. Valid log levels are
107
+ # `debug` and `info`, with `debug` being a little more verbose in places.
108
+ #
109
+ # Use of this configuration is only useful when `.logger` is _not_ set. When
110
+ # it is, the decision what levels to print is entirely deferred to the logger.
111
+ def self.log_level
112
+ @log_level
113
+ end
114
+
115
+ def self.log_level=(val)
116
+ raise ArgumentError, 'log_level should only be set to `nil`, `debug` or `info`' if !val.nil? && ![LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO].include?(val)
117
+
118
+ @log_level = val
119
+ end
120
+
121
+ # Sets a logger to which logging output will be sent. The logger should
122
+ # support the same interface as the `Logger` class that's part of Ruby's
123
+ # standard library (hint, anything in `Rails.logger` will likely be
124
+ # suitable).
125
+ #
126
+ # If `.logger` is set, the value of `.log_level` is ignored. The decision on
127
+ # what levels to print is entirely deferred to the logger.
128
+ def self.logger
129
+ @logger
130
+ end
131
+
132
+ def self.logger=(val)
133
+ @logger = val
134
+ end
135
+
136
+ def self.max_network_retries
137
+ @max_network_retries
138
+ end
139
+
140
+ def self.max_network_retries=(val)
141
+ @max_network_retries = val.to_i
142
+ end
143
+ end
144
+
145
+ Supercast.log_level = ENV['SUPERCAST_LOG'] unless ENV['SUPERCAST_LOG'].nil?
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../../lib/supercast.rb', __dir__)
4
+
5
+ RSpec.describe Supercast::Singleton do
6
+ describe 'self.resource_url' do
7
+ it 'should raise error with abstract class' do
8
+ expect { Supercast::Singleton.resource_url }.to raise_error(NotImplementedError)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../../lib/supercast.rb', __dir__)
4
+
5
+ RSpec.describe Supercast::VERSION do
6
+ it 'should be defined' do
7
+ defined?(Supercast::VERSION).should be_truthy
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../lib/supercast.rb', __dir__)
4
+
5
+ RSpec.describe Supercast do
6
+ it 'should allow api_key to be configured' do
7
+ Supercast.api_key = '123abc'
8
+
9
+ Supercast.api_key.should eq('123abc')
10
+ end
11
+
12
+ it 'should allow ca_bundle_path to be configured' do
13
+ Supercast.ca_bundle_path = '/path/to/bundle'
14
+
15
+ Supercast.ca_bundle_path.should eq('/path/to/bundle')
16
+ end
17
+
18
+ it 'should allow log_level to be configured' do
19
+ Supercast.log_level = Supercast::LEVEL_DEBUG
20
+
21
+ Supercast.log_level.should eq(Supercast::LEVEL_DEBUG)
22
+ end
23
+
24
+ it 'should raise error on invalid log_level configuration' do
25
+ expect { Supercast.log_level = 'bad' }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it 'should allow logger to be configured' do
29
+ Supercast.logger = 1
30
+
31
+ Supercast.logger.should eq(1)
32
+ end
33
+
34
+ it 'should allow max_network_retries to be configured' do
35
+ Supercast.max_network_retries = 1
36
+
37
+ Supercast.max_network_retries.should eq(1)
38
+ end
39
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+
5
+ SimpleCov.start 'rails' do
6
+ add_filter 'app/admin'
7
+ add_filter 'app/_docs'
8
+ end
9
+
10
+ # This file was generated by the `rspec --init` command. Conventionally, all
11
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
13
+ # this file to always be loaded, without a need to explicitly require it in any
14
+ # files.
15
+ #
16
+ # Given that it is always loaded, you are encouraged to keep this file as
17
+ # light-weight as possible. Requiring heavyweight dependencies from this file
18
+ # will add to the boot time of your test suite on EVERY test run, even for an
19
+ # individual file that may not need all of that loaded. Instead, consider making
20
+ # a separate helper file that requires the additional dependencies and performs
21
+ # the additional setup, and require it from the spec files that actually need
22
+ # it.
23
+ #
24
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
25
+ RSpec.configure do |config|
26
+ # rspec-expectations config goes here. You can use an alternate
27
+ # assertion/expectation library such as wrong or the stdlib/minitest
28
+ # assertions if you prefer.
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+
39
+ expectations.syntax = %i[should expect]
40
+ end
41
+
42
+ # rspec-mocks config goes here. You can use an alternate test double
43
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
44
+ config.mock_with :rspec do |mocks|
45
+ # Prevents you from mocking or stubbing a method that does not exist on
46
+ # a real object. This is generally recommended, and will default to
47
+ # `true` in RSpec 4.
48
+ mocks.verify_partial_doubles = true
49
+
50
+ mocks.syntax = %i[should expect]
51
+ end
52
+
53
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
54
+ # have no way to turn it off -- the option exists only for backwards
55
+ # compatibility in RSpec 3). It causes shared context metadata to be
56
+ # inherited by the metadata hash of host groups and examples, rather than
57
+ # triggering implicit auto-inclusion in groups with matching metadata.
58
+ config.shared_context_metadata_behavior = :apply_to_host_groups
59
+
60
+ # The settings below are suggested to provide a good initial experience
61
+ # with RSpec, but feel free to customize to your heart's content.
62
+ # # This allows you to limit a spec run to individual examples or groups
63
+ # # you care about by tagging them with `:focus` metadata. When nothing
64
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
65
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
66
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
67
+ # config.filter_run_when_matching :focus
68
+ #
69
+ # # Allows RSpec to persist some state between runs in order to support
70
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
71
+ # # you configure your source control system to ignore this file.
72
+ # config.example_status_persistence_file_path = "spec/examples.txt"
73
+ #
74
+ # # Limits the available syntax to the non-monkey patched syntax that is
75
+ # # recommended. For more details, see:
76
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
77
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
78
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
79
+ # config.disable_monkey_patching!
80
+ #
81
+ # # This setting enables warnings. It's recommended, but in some cases may
82
+ # # be too noisy due to issues in dependencies.
83
+ # config.warnings = true
84
+ #
85
+ # # Many RSpec users commonly either run the entire suite or an individual
86
+ # # file, and it's useful to allow more verbose output when running an
87
+ # # individual spec file.
88
+ # if config.files_to_run.one?
89
+ # # Use the documentation formatter for detailed output,
90
+ # # unless a formatter has already been configured
91
+ # # (e.g. via a command-line flag).
92
+ # config.default_formatter = "doc"
93
+ # end
94
+ #
95
+ # # Print the 10 slowest examples and example groups at the
96
+ # # end of the spec run, to help surface which specs are running
97
+ # # particularly slow.
98
+ # config.profile_examples = 10
99
+ #
100
+ # # Run specs in random order to surface order dependencies. If you find an
101
+ # # order dependency and want to debug it, you can fix the order by providing
102
+ # # the seed, which is printed after each run.
103
+ # # --seed 1234
104
+ # config.order = :random
105
+ #
106
+ # # Seed global randomization in this process using the `--seed` CLI option.
107
+ # # Setting this allows you to use `--seed` to deterministically reproduce
108
+ # # test failures related to randomization by passing the same `--seed` value
109
+ # # as the one that triggered the failure.
110
+ # Kernel.srand config.seed
111
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: supercast
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Ell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-11 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: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-http-persistent
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shoulda-matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.16.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.16.1
83
+ description: Supercast ruby client
84
+ email:
85
+ - info@supercast.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - bin/supercast-console.rb
91
+ - lib/supercast.rb
92
+ - lib/supercast/client.rb
93
+ - lib/supercast/data_list.rb
94
+ - lib/supercast/data_object.rb
95
+ - lib/supercast/data_types.rb
96
+ - lib/supercast/errors.rb
97
+ - lib/supercast/operations/create.rb
98
+ - lib/supercast/operations/destroy.rb
99
+ - lib/supercast/operations/list.rb
100
+ - lib/supercast/operations/request.rb
101
+ - lib/supercast/operations/save.rb
102
+ - lib/supercast/resource.rb
103
+ - lib/supercast/resources.rb
104
+ - lib/supercast/resources/channel.rb
105
+ - lib/supercast/resources/creator.rb
106
+ - lib/supercast/resources/episode.rb
107
+ - lib/supercast/resources/invite.rb
108
+ - lib/supercast/resources/role.rb
109
+ - lib/supercast/resources/subscriber.rb
110
+ - lib/supercast/resources/usage_alert.rb
111
+ - lib/supercast/response.rb
112
+ - lib/supercast/singleton.rb
113
+ - lib/supercast/util.rb
114
+ - lib/supercast/version.rb
115
+ - spec/lib/supercast/resource_spec.rb
116
+ - spec/lib/supercast/version_spec.rb
117
+ - spec/lib/supercast_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/company-z/supercast-api-ruby
120
+ licenses:
121
+ - Apache-2.0
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A HTTP client for accessing Supercast services.
143
+ test_files:
144
+ - spec/spec_helper.rb
145
+ - spec/lib/supercast_spec.rb
146
+ - spec/lib/supercast/resource_spec.rb
147
+ - spec/lib/supercast/version_spec.rb