uscreen_api 0.1.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: 7eb14d38f28ebdd8aedd1deedabf0977b33dbb52cedb22c2921c753152bb17d5
4
+ data.tar.gz: a4c4c4882e9a4b832d03497dac3e0c52c8b8d1a83d84663c9c85a97246b900ae
5
+ SHA512:
6
+ metadata.gz: 0ac100e9869c6963735ad891b770019e858c23aeb8bba1b934f8a5c34e730ea203fae024797e0447d6dac30728783aa5b259e96dbaff62e38b255df7db62d987
7
+ data.tar.gz: 3f2f2cfc17284449ad7af18d90c56d9955cdb701ad70333d0d2c308fd8e774defff0131bc77b3938fc41d1880b9fdd33f8f628e2478c2416809152a4a5edf501
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Andrei Bondarev
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,32 @@
1
+ # UscreenAPI
2
+
3
+ Client library for the [Uscreen.tv](https://www.uscreen.tv/) APIs.
4
+
5
+ ![Tests status](https://github.com/andreibondarev/uscreen_api/actions/workflows/ci.yml/badge.svg)
6
+ [![Gem Version](https://badge.fury.io/rb/uscreen_api.svg)](https://badge.fury.io/rb/uscreen_api)
7
+ [![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/uscreen_api)
8
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/uscreen_api/blob/main/LICENSE.txt)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ gem install uscreen_api
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ TODO: Write usage instructions here
19
+
20
+ ## Development
21
+
22
+ 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.
23
+
24
+ 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).
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andreibondarev/uscreen_api.
29
+
30
+ ## License
31
+
32
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,19 @@
1
+ module UscreenAPI
2
+ class Base
3
+ attr_reader :client
4
+
5
+ def initialize(client:)
6
+ @client = client
7
+ end
8
+
9
+ private
10
+
11
+ def handle_errors(status, body)
12
+ case status
13
+ when 401 then raise UscreenAPI::Errors::Unauthorized.new(body)
14
+ when 404 then raise UscreenAPI::Errors::UserNotFound.new(body)
15
+ when 422 then raise UscreenAPI::Errors::UserNotCreated.new(body)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+
5
+ module UscreenAPI
6
+ class Client
7
+ attr_reader :api_key
8
+
9
+ BASE_URL = "https://www.uscreen.io/publisher_api/v1/"
10
+
11
+ def initialize(api_key:)
12
+ @api_key = api_key
13
+ end
14
+
15
+ def customers
16
+ @customers ||= UscreenAPI::Customers.new(client: self)
17
+ end
18
+
19
+ def connection
20
+ @connection = Faraday.new(
21
+ url: BASE_URL,
22
+ headers: {
23
+ "Content-Type": "application/json",
24
+ Authorization: api_key
25
+ }
26
+ ) do |f|
27
+ f.request(:json)
28
+ f.response(:json)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UscreenAPI
4
+ class Customers < Base
5
+ PATH = "customers"
6
+
7
+ # Get paginated list of customers
8
+ # @param page [Integer] Page number
9
+ # @param from [String] Starting date and time for the filter range, formatted in RFC 3339. Example: 2023-01-01T00:00:00Z
10
+ # @param to [String] Ending date and time for the filter range, formatted in RFC 3339. Example: 2023-01-01T00:00:00Z
11
+ # @param date_field [String] Date field to filter by. Available fields: created_at, updated_at. Default: created_at. If not set, created_at is used.
12
+ def list(
13
+ page: nil,
14
+ from: nil,
15
+ to: nil,
16
+ date_field: nil
17
+ )
18
+ response = client.connection.get(PATH) do |req|
19
+ req.params = {}
20
+
21
+ req.params["page"] = page if page
22
+ req.params["from"] = from if from
23
+ req.params["to"] = to if to
24
+ req.params["date_field"] = date_field if date_field
25
+ end
26
+
27
+ handle_errors(response.status, response.body)
28
+
29
+ response.body
30
+ end
31
+
32
+ # Invite a new customer
33
+ # @param email [String] Customer email
34
+ # @param name [String] Customer name
35
+ # @param password [String] Customer password
36
+ # @param payment_user_id [String] Payment user ID
37
+ # @param skip_invite [Boolean] Skip invite email
38
+ # @param opted_in_for_news_and_updates [Boolean] Opted in for news and updates
39
+ # @param custom_fields [Hash] Custom fields
40
+ def create(
41
+ email:,
42
+ name:,
43
+ password:,
44
+ payment_user_id: nil,
45
+ skip_invite: nil,
46
+ opted_in_for_news_and_updates: nil,
47
+ custom_fields: {}
48
+ )
49
+ response = client.connection.post(PATH) do |req|
50
+ req.body = {}
51
+
52
+ req.body["email"] = email if email
53
+ req.body["name"] = name if name
54
+ req.body["password"] = password if password
55
+ req.body["payment_user_id"] = payment_user_id if payment_user_id
56
+ req.body["skip_invite"] = skip_invite if skip_invite
57
+ req.body["opted_in_for_news_and_updates"] = opted_in_for_news_and_updates if opted_in_for_news_and_updates
58
+
59
+ custom_fields.each { |key, value| req.body[key] = value } if custom_fields.any?
60
+ end
61
+
62
+ handle_errors(response.status, response.body)
63
+
64
+ response.body
65
+ end
66
+
67
+ # Get a customer information
68
+ # @param id [Integer] Customer ID or Email
69
+ def get(id:)
70
+ response = client.connection.get("#{PATH}/#{id}")
71
+
72
+ handle_errors(response.status, response.body)
73
+
74
+ response.body
75
+ end
76
+
77
+ # Update a customer information
78
+ # @param id [Integer] Customer ID or Email
79
+ # @param email [String] New customer email
80
+ # @param name [String] New customer name
81
+ # @param password [String] New customer password
82
+ # @param custom_fields [Hash] Custom fields
83
+ def update(
84
+ id:,
85
+ email: nil,
86
+ name: nil,
87
+ password: nil,
88
+ custom_fields: {}
89
+ )
90
+ response = client.connection.put("#{PATH}/#{id}") do |req|
91
+ req.body = {}
92
+
93
+ req.body["email"] = email if email
94
+ req.body["name"] = name if name
95
+ req.body["password"] = password if password
96
+
97
+ custom_fields.each { |key, value| req.body[key] = value } if custom_fields.any?
98
+ end
99
+
100
+ handle_errors(response.status, response.body)
101
+
102
+ response.body
103
+ end
104
+
105
+ # Generates a Single Sign-On link for a customer
106
+ # @param id [Integer] Customer ID or Email
107
+ def tokenized_url(id:)
108
+ response = client.connection.post("#{PATH}/#{id}/tokenized_url")
109
+ handle_errors(response.status, response.body)
110
+
111
+ response.body
112
+ end
113
+
114
+ # Get paginated list of accesses for a customer
115
+ # @param id [Integer] Customer ID or Email
116
+ # @param page [Integer] Page number
117
+ # @param from [String] Starting date and time for the filter range, formatted in RFC 3339. Example: 2023-01-01T00:00:00Z
118
+ # @param to [String] Ending date and time for the filter range, formatted in RFC 3339. Example: 2023-01-01T00:00:00Z
119
+ def accesses(
120
+ id:,
121
+ page: nil,
122
+ from: nil,
123
+ to: nil
124
+ )
125
+ response = client.connection.get("#{PATH}/#{id}/accesses")
126
+ handle_errors(response.status, response.body)
127
+
128
+ response.body
129
+ end
130
+
131
+ # Grant access to a customer
132
+ # @param id [Integer] Customer ID or Email
133
+ # @param product_id [Integer] Product ID
134
+ # @param product_type [String] Uscreen system product type. Can be a program|recurring|rent|freebie|fixed_price
135
+ # @param perform_action_at [String] Seconds since the Epoch. Next perform action needed in case of rent or recurring product types. System will add next due automatically in case of a blank field. example: 2024-07-05T13:47:52Z
136
+ # @param with_manual_billing [Boolean] Allows you to process billing outside the Uscreen platform. Default false.
137
+ def grant_access(
138
+ id:,
139
+ product_id:,
140
+ product_type:,
141
+ perform_action_at: nil,
142
+ with_manual_billing: false
143
+ )
144
+ response = client.connection.post("#{PATH}/#{id}/accesses") do |req|
145
+ req.body = {
146
+ product_id: product_id,
147
+ product_type: product_type,
148
+ with_manual_billing: with_manual_billing
149
+ }
150
+ req.body["perform_action_at"] = perform_action_at if perform_action_at
151
+ end
152
+
153
+ handle_errors(response.status, response.body)
154
+
155
+ response.body
156
+ end
157
+
158
+ # Revoke access by ID
159
+ # @param id [Integer] Customer ID or Email
160
+ # @param access_id [Integer] Access ID
161
+ def revoke_access(
162
+ id:,
163
+ access_id:
164
+ )
165
+ response = client.connection.delete("#{PATH}/#{id}/accesses/#{access_id}")
166
+ handle_errors(response.status, response.body)
167
+
168
+ response.body
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UscreenAPI::Errors
4
+ class UserNotFound < StandardError; end
5
+
6
+ class UserNotCreated < StandardError; end
7
+
8
+ class Unauthorized < StandardError; end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UscreenAPI
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "uscreen_api/version"
4
+
5
+ module UscreenAPI
6
+ autoload :Base, "uscreen_api/base"
7
+ autoload :Client, "uscreen_api/client"
8
+ autoload :Customers, "uscreen_api/customers"
9
+ autoload :Errors, "uscreen_api/errors"
10
+ end
@@ -0,0 +1,4 @@
1
+ module UscreenAPI
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uscreen_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrei Bondarev
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-01-07 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: pry-byebug
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: yard
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ description: Uscreen.tv Publisher API client
55
+ email:
56
+ - andrei.bondarev13@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE.txt
62
+ - README.md
63
+ - lib/uscreen_api.rb
64
+ - lib/uscreen_api/base.rb
65
+ - lib/uscreen_api/client.rb
66
+ - lib/uscreen_api/customers.rb
67
+ - lib/uscreen_api/errors.rb
68
+ - lib/uscreen_api/version.rb
69
+ - sig/uscreen_api.rbs
70
+ homepage: https://github.com/andreibondarev/uscreen_api
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ homepage_uri: https://github.com/andreibondarev/uscreen_api
75
+ source_code_uri: https://github.com/andreibondarev/uscreen_api
76
+ changelog_uri: https://github.com/andreibondarev/uscreen_api/CHANGELOG.md
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.0.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.6.2
92
+ specification_version: 4
93
+ summary: Uscreen.tv Publisher API client
94
+ test_files: []