linketysplit 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/lib/linketysplit/api_endpoints.rb +84 -0
- data/lib/linketysplit/publication_sdk.rb +46 -0
- data/lib/linketysplit/version.rb +3 -0
- data/lib/linketysplit.rb +6 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ee44a0b1f2a131b41e472206c3bd2cea44a63012f064de1952e0f91a01ea90c4
|
4
|
+
data.tar.gz: ebab559af5f7228e270bd6d203e94cc3eca48b874287aa9e551d5e61d909808b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d8692ef4d2f8da658c7c4bb7874265ef403a4d158d9844877b446cf03b422fced79b3d53823867112dbec72407041593c00f50eb0d0d1ace5d4440bdd8e9d32
|
7
|
+
data.tar.gz: 4a3ddadf7e066661d77a9d995487cc305443417cccb62f34eacae3b10c7b566ed6611377afdcd2d2a6a79e8b3683827d0edf610c48406fa224c44b667c1c3b79
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Christopher Carson
|
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,42 @@
|
|
1
|
+
# linketysplit
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/linketysplit)
|
4
|
+
[](https://www.ruby-toolbox.com/projects/linketysplit)
|
5
|
+
[](https://github.com/LinketySplit/linketysplit-ruby/actions/workflows/ci.yml)
|
6
|
+
[](https://codeclimate.com/github/LinketySplit/linketysplit-ruby)
|
7
|
+
|
8
|
+
TODO: Description of this gem goes here.
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
- [Quick start](#quick-start)
|
13
|
+
- [Support](#support)
|
14
|
+
- [License](#license)
|
15
|
+
- [Code of conduct](#code-of-conduct)
|
16
|
+
- [Contribution guide](#contribution-guide)
|
17
|
+
|
18
|
+
## Quick start
|
19
|
+
|
20
|
+
```
|
21
|
+
gem install linketysplit
|
22
|
+
```
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require "linketysplit"
|
26
|
+
```
|
27
|
+
|
28
|
+
## Support
|
29
|
+
|
30
|
+
If you want to report a bug, or have ideas, feedback or questions about the gem, [let me know via GitHub issues](https://github.com/LinketySplit/linketysplit-ruby/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
35
|
+
|
36
|
+
## Code of conduct
|
37
|
+
|
38
|
+
Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
39
|
+
|
40
|
+
## Contribution guide
|
41
|
+
|
42
|
+
Pull requests are welcome!
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "typhoeus"
|
2
|
+
require "json"
|
3
|
+
require "cgi"
|
4
|
+
|
5
|
+
module Linketysplit
|
6
|
+
class ApiEndpointFailedError < StandardError; end
|
7
|
+
|
8
|
+
class ApiError < StandardError
|
9
|
+
attr_reader :status_code
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@status_code = response.code
|
13
|
+
data = JSON.parse(response.body)
|
14
|
+
message = data["message"].is_a?(String) ? data["message"] : "An unknown error occurred"
|
15
|
+
super(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ApiEndpoints
|
20
|
+
attr_reader :linketysplit_origin,
|
21
|
+
:api_key
|
22
|
+
|
23
|
+
def initialize(api_key, linketysplit_origin="https://linketysplit.com")
|
24
|
+
@api_key = api_key
|
25
|
+
@linketysplit_origin = linketysplit_origin
|
26
|
+
end
|
27
|
+
|
28
|
+
def handle_response(response)
|
29
|
+
if response.success?
|
30
|
+
{ error: nil, data: JSON.parse(response.body) }
|
31
|
+
elsif response.timed_out?
|
32
|
+
{ error: ApiEndpointFailedError.new("API request to #{url} timed out"), data: nil }
|
33
|
+
elsif response.code == 0
|
34
|
+
{ error: ApiEndpointFailedError.new("API request to #{url} failed"), data: nil }
|
35
|
+
else
|
36
|
+
{ error: ApiError.new(response), data: nil }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def get(url)
|
41
|
+
response = Typhoeus.get(
|
42
|
+
url,
|
43
|
+
headers: { "Authorization" => "Bearer #{api_key}", "Accept" => "application/json" }
|
44
|
+
)
|
45
|
+
handle_response(response)
|
46
|
+
end
|
47
|
+
|
48
|
+
def post(url, data)
|
49
|
+
response = Typhoeus.post(
|
50
|
+
url,
|
51
|
+
headers: {
|
52
|
+
"Authorization" => "Bearer #{api_key}",
|
53
|
+
"Content-Type" => "application/json",
|
54
|
+
"Accept" => "application/json"
|
55
|
+
},
|
56
|
+
body: JSON.dump(data)
|
57
|
+
)
|
58
|
+
handle_response(response)
|
59
|
+
end
|
60
|
+
|
61
|
+
def publication
|
62
|
+
url = "#{linketysplit_origin}/api/v1/publication"
|
63
|
+
get(url)
|
64
|
+
end
|
65
|
+
|
66
|
+
def article(permalink)
|
67
|
+
encoded_permalink = CGI.escape(permalink)
|
68
|
+
url = "#{linketysplit_origin}/api/v1/publication/article/#{encoded_permalink}"
|
69
|
+
get(url)
|
70
|
+
end
|
71
|
+
|
72
|
+
def upsert_article(permalink)
|
73
|
+
url = "#{linketysplit_origin}/api/v1/publication/article"
|
74
|
+
data = { permalink: }
|
75
|
+
post(url, data)
|
76
|
+
end
|
77
|
+
|
78
|
+
def verify_article_access(article_access_id)
|
79
|
+
url = "#{linketysplit_origin}/api/v1/publication/verify-article-access"
|
80
|
+
data = { articleAccessId: article_access_id }
|
81
|
+
post(url, data)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "jwt"
|
2
|
+
require "base64"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Linketysplit
|
6
|
+
class PublicationSdk
|
7
|
+
attr_reader :api_key
|
8
|
+
|
9
|
+
def initialize(api_key)
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
# Creates a signed article purchase link with the given permalink.
|
14
|
+
#
|
15
|
+
# @param permalink [String] The canonical URL of the article.
|
16
|
+
# @param customPricing [Hash, nil] Optional. Custom pricing to be applied for this purchase link,
|
17
|
+
# that is, for a particular user.
|
18
|
+
# - `:price` [Integer] The base article price in US cents.
|
19
|
+
# - `:discounts` [Array<Hash>] Optional. Quantity discounts.
|
20
|
+
# - `:quantity` [Integer] The minimum quantity at which the discount applies.
|
21
|
+
# - `:price` [Integer] The unit price of the article at the given quantity.
|
22
|
+
# @param context [String, nil] Optional. Pass "sharing" if the user is sharing an article.
|
23
|
+
# @return [String] The URL of the purchase page on LinketySplit. Show the reader a link to this URL.
|
24
|
+
def create_article_purchase_link(permalink, custom_pricing=nil, context=nil)
|
25
|
+
payload = {
|
26
|
+
permalink:
|
27
|
+
}
|
28
|
+
|
29
|
+
payload[:customPricing] = custom_pricing if custom_pricing
|
30
|
+
|
31
|
+
payload[:context] = context if context
|
32
|
+
token = JWT.encode payload, @api_key, "HS256"
|
33
|
+
"https://linketysplit.com/purchase-link/#{token}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_linketysplit_pricing_meta_tag(article_pricing)
|
37
|
+
content = Base64.encode64(JSON.dump(article_pricing))
|
38
|
+
"<meta property=\"linketysplit:pricing\" content=\"#{content}\" />"
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.get_linketysplit_enabled_meta_tag(enabled: true)
|
42
|
+
content = enabled ? "true" : "false"
|
43
|
+
"<meta property=\"linketysplit:enabled\" content=\"#{content}\" />"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/linketysplit.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linketysplit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Carson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jwt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.8.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.8.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oga
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: typhoeus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.4'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- chris@nowzoo.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- lib/linketysplit.rb
|
65
|
+
- lib/linketysplit/api_endpoints.rb
|
66
|
+
- lib/linketysplit/publication_sdk.rb
|
67
|
+
- lib/linketysplit/version.rb
|
68
|
+
homepage: https://github.com/LinketySplit/linketysplit-ruby
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
bug_tracker_uri: https://github.com/LinketySplit/linketysplit-ruby/issues
|
73
|
+
changelog_uri: https://github.com/LinketySplit/linketysplit-ruby/releases
|
74
|
+
source_code_uri: https://github.com/LinketySplit/linketysplit-ruby
|
75
|
+
homepage_uri: https://github.com/LinketySplit/linketysplit-ruby
|
76
|
+
rubygems_mfa_required: 'true'
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.1'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.5.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: SDK for interactiong with LinketySplit
|
96
|
+
test_files: []
|