ohspotted 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 +21 -0
- data/README.md +151 -0
- data/examples/README.md +10 -0
- data/examples/json.rb +8 -0
- data/examples/request.rb +11 -0
- data/lib/ohspotted/client.rb +241 -0
- data/lib/ohspotted/endpoints.rb +72 -0
- data/lib/ohspotted/errors.rb +47 -0
- data/lib/ohspotted/operations.rb +114 -0
- data/lib/ohspotted/responses.rb +45 -0
- data/lib/ohspotted/serialization.rb +66 -0
- data/lib/ohspotted/transport.rb +27 -0
- data/lib/ohspotted/version.rb +5 -0
- data/lib/ohspotted.rb +14 -0
- data/sig/ohspotted.rbs +83 -0
- metadata +64 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5b6e4d4c5cd812cb536a7fe6c193c2392a7cbf87de6c863ef42d6f0b1395ad0d
|
|
4
|
+
data.tar.gz: 0de782edccefe080110074f09d038487e3531d2f4949ce8d91c8a8effe83bf02
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 244fb729c481b4015868b43b9c20d19a57d3547a6341403218485d3ae4ccab51f2abe0b6f432e94214a8966dee177aa0df30ee12e015be08db585d714fb0ba53
|
|
7
|
+
data.tar.gz: be8e483265cf5d5ed0e5dd4f6c39be30654a093504423ce959b16bf7d40c83c42e663a7ecaea532fdf0e4bd33b8adbe52d0c1dc0551d0f67fe63e8d071a90ba0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OhSpotted
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# OhSpotted Ruby SDK
|
|
2
|
+
|
|
3
|
+
The official Ruby SDK for the [OhSpotted](https://www.ohspotted.com) LinkedIn change tracking API.
|
|
4
|
+
|
|
5
|
+
Follow public LinkedIn profiles, company pages and jobs, and read what changed on them as signals, checked once a day.
|
|
6
|
+
|
|
7
|
+
The SDK exposes **9 methods**, one per documented endpoint, plus a generic `request`. It only uses the Ruby standard library.
|
|
8
|
+
|
|
9
|
+
## Requirements
|
|
10
|
+
|
|
11
|
+
- Ruby 3.1 or newer
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
gem install ohspotted
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or in your `Gemfile`:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem "ohspotted"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Get your API key
|
|
26
|
+
|
|
27
|
+
[Sign up for OhSpotted](https://www.ohspotted.com/signup) or sign in, then copy your API key from the [dashboard](https://www.ohspotted.com/app). The client reads `ENV["OHSPOTTED_API_KEY"]` when no key is passed.
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require "ohspotted"
|
|
33
|
+
|
|
34
|
+
client = OhSpotted::Client.new(api_key: ENV.fetch("OHSPOTTED_API_KEY"))
|
|
35
|
+
response = client.add_target(url: "https://www.linkedin.com/company/linkedin")
|
|
36
|
+
puts response.data
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Keyword arguments use the parameter names of the [API reference](https://www.ohspotted.com/docs). Unknown names raise `OhSpotted::SerializationError`; use `request` for undocumented parameters.
|
|
40
|
+
|
|
41
|
+
## HTTP methods
|
|
42
|
+
|
|
43
|
+
Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body. Null values are never sent.
|
|
44
|
+
|
|
45
|
+
`nil` values are omitted, `false` and `0` are sent, and arrays repeat the parameter name.
|
|
46
|
+
|
|
47
|
+
## Any endpoint
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
response = client.request("GET", "/account")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Errors
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
begin
|
|
57
|
+
client.add_target(url: "https://www.linkedin.com/company/linkedin")
|
|
58
|
+
rescue OhSpotted::APIError => e
|
|
59
|
+
warn "HTTP #{e.status}: #{e.message}"
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
| Error | When |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| `OhSpotted::ConfigurationError` | Missing API key, invalid options or unsupported method. |
|
|
66
|
+
| `OhSpotted::SerializationError` | A required parameter is missing, unknown or can't be sent. |
|
|
67
|
+
| `OhSpotted::TransportError` | Network failure or timeout. |
|
|
68
|
+
| `OhSpotted::APIError` | Non-2xx status (`status`, `error_code`, `error_message`, `response_body`, `raw_response`). `error_code` is the API's `error.code`, such as `"no_credits"` or `"target_limit"`, or `nil` when the body has none. |
|
|
69
|
+
| `OhSpotted::ResponseDecodingError` | A success response could not be decoded. |
|
|
70
|
+
|
|
71
|
+
All of them inherit from `OhSpotted::Error`.
|
|
72
|
+
|
|
73
|
+
## Retries
|
|
74
|
+
|
|
75
|
+
Requests are retried up to 3 times after a network error, a `408`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402`, `404` or `429`, and client-side timeouts are not retried: the API's rate limits last until the hour (or the day) is over, and on the free plan every retry would count as a request. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
client = OhSpotted::Client.new(max_retries: 5, retry_delay: 0.5)
|
|
79
|
+
client.add_target(url: "https://www.linkedin.com/company/linkedin", request_options: { max_retries: 0 }) # one request without retries
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Batch requests
|
|
83
|
+
|
|
84
|
+
`batch` runs the block for every item on 10 threads (`concurrency:`) and returns one `BatchResult` per item, in input order. A failing item never stops the others.
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
inputs = ["https://www.linkedin.com/company/linkedin", "https://www.linkedin.com/company/microsoft", "https://www.linkedin.com/company/github"]
|
|
88
|
+
results = client.batch(inputs, concurrency: 5) { |value| client.add_target(url: value) }
|
|
89
|
+
results.each do |result|
|
|
90
|
+
if result.ok?
|
|
91
|
+
puts result.value.data
|
|
92
|
+
else
|
|
93
|
+
warn "#{inputs[result.index]}: #{result.error.message}"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
| Constant | Default | Description |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `OhSpotted::Client::DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
|
|
101
|
+
| `OhSpotted::Client::DEFAULT_TIMEOUT` | `120` | Request timeout (seconds) |
|
|
102
|
+
| `OhSpotted::Client::MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
|
|
103
|
+
| `OhSpotted::Client::RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
|
|
104
|
+
| `OhSpotted::Client::DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
|
|
105
|
+
|
|
106
|
+
## Timeouts and custom transports
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
client = OhSpotted::Client.new(timeout: 60) # seconds, default 120
|
|
110
|
+
client.add_target(url: "https://www.linkedin.com/company/linkedin", request_options: { timeout: 30 })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
A transport is any object with `call(method:, url:, headers:, body:, timeout:)` returning `[status, headers, body]`; the default is `OhSpotted::NetHTTPTransport`.
|
|
114
|
+
|
|
115
|
+
## Endpoints
|
|
116
|
+
|
|
117
|
+
9 methods, generated from the [OpenAPI document](https://www.ohspotted.com/openapi.json).
|
|
118
|
+
|
|
119
|
+
| Method | HTTP | Description |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `add_target` | POST `/targets` | Adds a LinkedIn profile, company page or job to the list. The first read happens shortly after, usually within minutes, and only takes the… |
|
|
122
|
+
| `get_target` | GET `/targets/{id}` | One target, with its latest signal. |
|
|
123
|
+
| `get_usage` | GET `/usage` | The plan, the credits left, how many pages are followed and how many the plan allows, and the credits the active pages use in 30 days. Ever… |
|
|
124
|
+
| `list_signals` | GET `/signals` | The signals found on every page of the list since each was added, newest first: the same as The Tea in the app. |
|
|
125
|
+
| `list_target_signals` | GET `/targets/{id}/signals` | The signals found on one page since the account added it, newest first. A signal is a change between two daily reads: nothing is found betw… |
|
|
126
|
+
| `list_targets` | GET `/targets` | The account's list, newest first, with each page's state and its latest signal. A target is a LinkedIn profile, company page or job followe… |
|
|
127
|
+
| `mark_signals_seen` | POST `/signals/seen` | Marks every signal found so far as seen, on every page of the list. No body is needed. For one page, send seen: true to PATCH /targets/{id}. |
|
|
128
|
+
| `remove_target` | DELETE `/targets/{id}` | Takes the page off the list. Its signals are no longer shown to the account; nothing else changes for the people who follow it too. |
|
|
129
|
+
| `update_target` | PATCH `/targets/{id}` | Send paused, muted and/or seen. A paused page isn't read and costs nothing; a muted page is still read and its signals are kept, but it isn… |
|
|
130
|
+
|
|
131
|
+
## All OhSpotted SDKs
|
|
132
|
+
|
|
133
|
+
| SDK | Package | Install |
|
|
134
|
+
| --- | --- | --- |
|
|
135
|
+
| Node.js | [`@ohspotted/sdk`](https://www.npmjs.com/package/@ohspotted/sdk) | `npm install @ohspotted/sdk` |
|
|
136
|
+
| Python | [`ohspotted`](https://pypi.org/project/ohspotted/) | `pip install ohspotted` |
|
|
137
|
+
| Go | [`ohspotted-go`](https://pkg.go.dev/github.com/ohspotted/ohspotted-go) | `go get github.com/ohspotted/ohspotted-go` |
|
|
138
|
+
| .NET | [`OhSpotted`](https://www.nuget.org/packages/OhSpotted) | `dotnet add package OhSpotted` |
|
|
139
|
+
| Ruby | [`ohspotted`](https://rubygems.org/gems/ohspotted) | `gem install ohspotted` |
|
|
140
|
+
| PHP | [`ohspotted/sdk`](https://packagist.org/packages/ohspotted/sdk) | `composer require ohspotted/sdk` |
|
|
141
|
+
| Java | [`ohspotted-java`](https://github.com/ohspotted/ohspotted-java) | build from source, see its README |
|
|
142
|
+
| CLI | [`@ohspotted/cli`](https://www.npmjs.com/package/@ohspotted/cli) | `npm install -g @ohspotted/cli` |
|
|
143
|
+
| MCP server | [`@ohspotted/mcp`](https://www.npmjs.com/package/@ohspotted/mcp) | `npx -y @ohspotted/mcp` |
|
|
144
|
+
|
|
145
|
+
## Trademarks
|
|
146
|
+
|
|
147
|
+
LinkedIn® is a registered trademark of LinkedIn Corporation. OhSpotted is not affiliated with, endorsed or sponsored by LinkedIn.
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT — see [LICENSE](LICENSE).
|
data/examples/README.md
ADDED
data/examples/json.rb
ADDED
data/examples/request.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "ohspotted"
|
|
4
|
+
|
|
5
|
+
client = OhSpotted::Client.new # reads OHSPOTTED_API_KEY
|
|
6
|
+
begin
|
|
7
|
+
response = client.request("GET", "/account")
|
|
8
|
+
puts response.data if response.json?
|
|
9
|
+
rescue OhSpotted::APIError => e
|
|
10
|
+
warn "HTTP #{e.status}: #{e.message}"
|
|
11
|
+
end
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
module OhSpotted
|
|
6
|
+
# Official OhSpotted API client. Create one instance and reuse it.
|
|
7
|
+
class Client
|
|
8
|
+
include Operations
|
|
9
|
+
|
|
10
|
+
DEFAULT_BASE_URL = "https://www.ohspotted.com/api/v1"
|
|
11
|
+
DEFAULT_TIMEOUT = 120
|
|
12
|
+
# Tasks run at the same time by #batch.
|
|
13
|
+
DEFAULT_CONCURRENCY = 10
|
|
14
|
+
# Retries after a network error or a 408, 500, 502, 503 or 504 response (never a 429).
|
|
15
|
+
MAX_RETRIES = 3
|
|
16
|
+
# Each retry waits this many times longer than the previous one (a Retry-After header wins).
|
|
17
|
+
RETRY_BACKOFF_FACTOR = 1.5
|
|
18
|
+
# Seconds before the first retry.
|
|
19
|
+
DEFAULT_RETRY_DELAY = 1.0
|
|
20
|
+
MAX_RETRY_DELAY = 30.0
|
|
21
|
+
RETRYABLE_STATUSES = [408, 500, 502, 503, 504].freeze
|
|
22
|
+
API_KEY_ENVIRONMENT_VARIABLE = "OHSPOTTED_API_KEY"
|
|
23
|
+
ERROR_MESSAGE_KEYS = %w[error message error_message detail].freeze
|
|
24
|
+
|
|
25
|
+
# @param api_key [String, nil] defaults to ENV["OHSPOTTED_API_KEY"]
|
|
26
|
+
# @param base_url [String] API origin
|
|
27
|
+
# @param timeout [Numeric, nil] seconds per request; nil disables it
|
|
28
|
+
# @param headers [Hash] extra headers for every request
|
|
29
|
+
# @param max_retries [Integer] retries after a network error or a 408/5xx response; 0 disables them
|
|
30
|
+
# @param retry_delay [Numeric] seconds before the first retry, growing 1.5x per retry
|
|
31
|
+
# @param transport [#call] custom transport, see {NetHTTPTransport}
|
|
32
|
+
def initialize(api_key: nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, headers: {},
|
|
33
|
+
max_retries: MAX_RETRIES, retry_delay: DEFAULT_RETRY_DELAY, transport: nil)
|
|
34
|
+
api_key = ENV.fetch(API_KEY_ENVIRONMENT_VARIABLE, nil) if api_key.nil?
|
|
35
|
+
if !api_key.is_a?(String) || api_key.strip.empty?
|
|
36
|
+
raise ConfigurationError,
|
|
37
|
+
"A non-blank OhSpotted API key is required. Pass api_key: or set #{API_KEY_ENVIRONMENT_VARIABLE}."
|
|
38
|
+
end
|
|
39
|
+
raise ConfigurationError, "The OhSpotted API key cannot be used in an HTTP header." if api_key.match?(/[\r\n]/)
|
|
40
|
+
|
|
41
|
+
uri = URI.parse(base_url.to_s)
|
|
42
|
+
unless %w[http https].include?(uri.scheme) && uri.host
|
|
43
|
+
raise ConfigurationError, "base_url must be an absolute http or https URL."
|
|
44
|
+
end
|
|
45
|
+
raise ConfigurationError, "timeout must be a positive number or nil." if timeout && !(timeout.is_a?(Numeric) && timeout.positive?)
|
|
46
|
+
raise ConfigurationError, "transport must respond to #call." if transport && !transport.respond_to?(:call)
|
|
47
|
+
|
|
48
|
+
@api_key = api_key
|
|
49
|
+
@base_url = base_url.to_s.sub(%r{/+\z}, "")
|
|
50
|
+
@timeout = timeout
|
|
51
|
+
@headers = headers.to_h { |name, value| [name.to_s, value.to_s] }.freeze
|
|
52
|
+
raise ConfigurationError, "max_retries must be a non-negative Integer." unless max_retries.is_a?(Integer) && max_retries >= 0
|
|
53
|
+
raise ConfigurationError, "retry_delay must be a non-negative number." unless retry_delay.is_a?(Numeric) && retry_delay >= 0
|
|
54
|
+
|
|
55
|
+
@max_retries = max_retries
|
|
56
|
+
@retry_delay = retry_delay
|
|
57
|
+
@transport = transport || NetHTTPTransport.new
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def inspect
|
|
61
|
+
"#<#{self.class.name} base_url=#{@base_url.inspect}>"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Sends any request, including endpoints released after this SDK version.
|
|
65
|
+
# GET parameters travel in the query string; POST parameters travel in a JSON body.
|
|
66
|
+
# @return [JsonResponse, BinaryResponse]
|
|
67
|
+
def request(method, path, params = nil, timeout: nil, headers: nil, max_retries: nil)
|
|
68
|
+
send_request(method.to_s.upcase, path, params, { timeout: timeout, headers: headers, max_retries: max_retries }, :any)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Runs the block for every item on +concurrency+ threads (default 10) and returns one {BatchResult} per item,
|
|
72
|
+
# in input order. A failing item never stops the others; the client is thread-safe.
|
|
73
|
+
#
|
|
74
|
+
# results = client.batch(ids, concurrency: 5) { |id| client.some_endpoint(query: id) }
|
|
75
|
+
# @return [Array<BatchResult>]
|
|
76
|
+
def batch(items, concurrency: DEFAULT_CONCURRENCY)
|
|
77
|
+
raise ConfigurationError, "concurrency must be a positive Integer." unless concurrency.is_a?(Integer) && concurrency.positive?
|
|
78
|
+
raise ArgumentError, "batch needs a block" unless block_given?
|
|
79
|
+
|
|
80
|
+
list = items.to_a
|
|
81
|
+
results = Array.new(list.size)
|
|
82
|
+
queue = Queue.new
|
|
83
|
+
list.each_with_index { |item, index| queue << [item, index] }
|
|
84
|
+
queue.close
|
|
85
|
+
workers = Array.new([concurrency, list.size].min) do
|
|
86
|
+
Thread.new do
|
|
87
|
+
while (job = queue.pop)
|
|
88
|
+
item, index = job
|
|
89
|
+
results[index] = begin
|
|
90
|
+
BatchResult.new(index: index, value: yield(item), error: nil)
|
|
91
|
+
rescue StandardError => e
|
|
92
|
+
BatchResult.new(index: index, value: nil, error: e)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
workers.each(&:join)
|
|
98
|
+
results
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
private
|
|
102
|
+
|
|
103
|
+
def call_operation(name, params, options)
|
|
104
|
+
endpoint = ENDPOINTS.fetch(name)
|
|
105
|
+
options = (options || {}).transform_keys(&:to_sym)
|
|
106
|
+
method = (options[:method] || endpoint[:methods].first).to_s.upcase
|
|
107
|
+
unless endpoint[:methods].include?(method)
|
|
108
|
+
raise ConfigurationError, "#{endpoint[:path]} supports #{endpoint[:methods].join(', ')}, not #{method}."
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
params = params.transform_keys(&:to_s)
|
|
112
|
+
unknown = params.keys - endpoint[:params]
|
|
113
|
+
unless unknown.empty?
|
|
114
|
+
raise SerializationError.new(
|
|
115
|
+
"Unknown parameter(s) for #{name}: #{unknown.join(', ')}. Use #request for undocumented parameters.",
|
|
116
|
+
unknown.first
|
|
117
|
+
)
|
|
118
|
+
end
|
|
119
|
+
endpoint[:required].each do |required|
|
|
120
|
+
raise SerializationError.new("The \"#{required}\" parameter is required.", required) if params[required].nil?
|
|
121
|
+
end
|
|
122
|
+
send_request(method, endpoint[:path], params, options, endpoint[:response])
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def send_request(method, path, params, options, expected)
|
|
126
|
+
raise ConfigurationError, "Unsupported HTTP method: #{method.inspect}." unless %w[GET POST PATCH DELETE].include?(method)
|
|
127
|
+
raise ConfigurationError, 'The request path must start with "/".' unless path.is_a?(String) && path.start_with?("/")
|
|
128
|
+
|
|
129
|
+
path, pairs, body = Serialization.serialize(method, path, params)
|
|
130
|
+
url = @base_url + path
|
|
131
|
+
url += "?#{Serialization.encode_query(pairs)}" unless pairs.empty?
|
|
132
|
+
headers = {
|
|
133
|
+
"Accept" => "application/json, */*;q=0.8",
|
|
134
|
+
"User-Agent" => "ohspotted-ruby/#{VERSION}"
|
|
135
|
+
}.merge(@headers).merge((options[:headers] || {}).to_h { |k, v| [k.to_s, v.to_s] })
|
|
136
|
+
headers["Authorization"] = "Bearer #{@api_key}"
|
|
137
|
+
payload = nil
|
|
138
|
+
if body
|
|
139
|
+
headers["Content-Type"] = "application/json"
|
|
140
|
+
payload = JSON.generate(body)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
max_retries = options[:max_retries] || @max_retries
|
|
144
|
+
attempt = 0
|
|
145
|
+
loop do
|
|
146
|
+
begin
|
|
147
|
+
status, response_headers, response_body = @transport.call(
|
|
148
|
+
method: method, url: url, headers: headers, body: payload, timeout: options[:timeout] || @timeout
|
|
149
|
+
)
|
|
150
|
+
rescue Timeout::Error => e
|
|
151
|
+
raise TransportError, "OhSpotted request timed out: #{e.message}"
|
|
152
|
+
rescue StandardError => e
|
|
153
|
+
raise TransportError, "OhSpotted request failed before an HTTP response was received: #{e.message}" if attempt >= max_retries
|
|
154
|
+
|
|
155
|
+
sleep(retry_delay(attempt, nil))
|
|
156
|
+
attempt += 1
|
|
157
|
+
next
|
|
158
|
+
end
|
|
159
|
+
raw = build_raw_response(status, response_headers, response_body)
|
|
160
|
+
return decode(raw, expected) if (200..299).cover?(raw.status)
|
|
161
|
+
raise api_error(raw) unless retryable?(raw) && attempt < max_retries
|
|
162
|
+
|
|
163
|
+
sleep(retry_delay(attempt, raw.headers["retry-after"]&.first))
|
|
164
|
+
attempt += 1
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def retryable?(raw)
|
|
169
|
+
RETRYABLE_STATUSES.include?(raw.status)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def retry_delay(attempt, retry_after)
|
|
173
|
+
seconds = Float(retry_after, exception: false) if retry_after
|
|
174
|
+
return [seconds, 60].min if seconds && seconds >= 0
|
|
175
|
+
|
|
176
|
+
[@retry_delay * (RETRY_BACKOFF_FACTOR**attempt), MAX_RETRY_DELAY].min
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def build_raw_response(status, headers, body)
|
|
180
|
+
normalized = {}
|
|
181
|
+
(headers || {}).each { |name, values| normalized[name.to_s.downcase] = Array(values).map(&:to_s).freeze }
|
|
182
|
+
RawResponse.new(
|
|
183
|
+
status: status.to_i,
|
|
184
|
+
headers: normalized.freeze,
|
|
185
|
+
content_type: normalized["content-type"]&.first,
|
|
186
|
+
body: body.to_s.b
|
|
187
|
+
)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def api_error(raw)
|
|
191
|
+
parsed = parse_json(raw.body)
|
|
192
|
+
message = nil
|
|
193
|
+
code = nil
|
|
194
|
+
if parsed.is_a?(Hash)
|
|
195
|
+
# The API answers {"error": {"code", "message"}}.
|
|
196
|
+
message = parsed["error"]["message"] if parsed["error"].is_a?(Hash) && parsed["error"]["message"].is_a?(String)
|
|
197
|
+
code = parsed["error"]["code"] if parsed["error"].is_a?(Hash) && parsed["error"]["code"].is_a?(String)
|
|
198
|
+
ERROR_MESSAGE_KEYS.each do |key|
|
|
199
|
+
value = parsed[key]
|
|
200
|
+
if value.is_a?(String) && !value.empty?
|
|
201
|
+
message = value
|
|
202
|
+
break
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
APIError.new(raw_response: raw, response_body: parsed == NOT_JSON ? nil : parsed, error_message: message, error_code: code)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def decode(raw, expected)
|
|
210
|
+
unless json_media_type?(raw.content_type)
|
|
211
|
+
if expected == :json
|
|
212
|
+
raise ResponseDecodingError.new("OhSpotted returned a successful non-JSON response for a JSON operation.", raw)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
return BinaryResponse.new(bytes: raw.body, content_type: raw.content_type, raw_response: raw)
|
|
216
|
+
end
|
|
217
|
+
data = parse_json(raw.body)
|
|
218
|
+
if data == NOT_JSON
|
|
219
|
+
raise ResponseDecodingError.new("OhSpotted returned a successful JSON response that could not be decoded.", raw)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
JsonResponse.new(data: data, raw_response: raw)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
NOT_JSON = Object.new.freeze
|
|
226
|
+
private_constant :NOT_JSON
|
|
227
|
+
|
|
228
|
+
def parse_json(body)
|
|
229
|
+
JSON.parse(body.dup.force_encoding(Encoding::UTF_8))
|
|
230
|
+
rescue JSON::ParserError, EncodingError
|
|
231
|
+
NOT_JSON
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def json_media_type?(content_type)
|
|
235
|
+
return false if content_type.nil?
|
|
236
|
+
|
|
237
|
+
media_type = content_type.split(";", 2).first.strip.downcase
|
|
238
|
+
media_type == "application/json" || media_type.end_with?("+json")
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated from the OhSpotted OpenAPI document. Do not edit by hand.
|
|
4
|
+
|
|
5
|
+
module OhSpotted
|
|
6
|
+
# Path, methods, response kind and parameter names of every documented operation.
|
|
7
|
+
ENDPOINTS = {
|
|
8
|
+
"add_target" => {
|
|
9
|
+
path: "/targets",
|
|
10
|
+
methods: ["POST"].freeze,
|
|
11
|
+
response: :json,
|
|
12
|
+
required: ["url"].freeze,
|
|
13
|
+
params: ["url"].freeze
|
|
14
|
+
}.freeze,
|
|
15
|
+
"get_target" => {
|
|
16
|
+
path: "/targets/{id}",
|
|
17
|
+
methods: ["GET"].freeze,
|
|
18
|
+
response: :json,
|
|
19
|
+
required: ["id"].freeze,
|
|
20
|
+
params: ["id"].freeze
|
|
21
|
+
}.freeze,
|
|
22
|
+
"get_usage" => {
|
|
23
|
+
path: "/usage",
|
|
24
|
+
methods: ["GET"].freeze,
|
|
25
|
+
response: :json,
|
|
26
|
+
required: [].freeze,
|
|
27
|
+
params: [].freeze
|
|
28
|
+
}.freeze,
|
|
29
|
+
"list_signals" => {
|
|
30
|
+
path: "/signals",
|
|
31
|
+
methods: ["GET"].freeze,
|
|
32
|
+
response: :json,
|
|
33
|
+
required: [].freeze,
|
|
34
|
+
params: ["limit", "unread"].freeze
|
|
35
|
+
}.freeze,
|
|
36
|
+
"list_target_signals" => {
|
|
37
|
+
path: "/targets/{id}/signals",
|
|
38
|
+
methods: ["GET"].freeze,
|
|
39
|
+
response: :json,
|
|
40
|
+
required: ["id"].freeze,
|
|
41
|
+
params: ["id", "limit", "unread"].freeze
|
|
42
|
+
}.freeze,
|
|
43
|
+
"list_targets" => {
|
|
44
|
+
path: "/targets",
|
|
45
|
+
methods: ["GET"].freeze,
|
|
46
|
+
response: :json,
|
|
47
|
+
required: [].freeze,
|
|
48
|
+
params: ["url", "kind", "page", "limit"].freeze
|
|
49
|
+
}.freeze,
|
|
50
|
+
"mark_signals_seen" => {
|
|
51
|
+
path: "/signals/seen",
|
|
52
|
+
methods: ["POST"].freeze,
|
|
53
|
+
response: :json,
|
|
54
|
+
required: [].freeze,
|
|
55
|
+
params: [].freeze
|
|
56
|
+
}.freeze,
|
|
57
|
+
"remove_target" => {
|
|
58
|
+
path: "/targets/{id}",
|
|
59
|
+
methods: ["DELETE"].freeze,
|
|
60
|
+
response: :json,
|
|
61
|
+
required: ["id"].freeze,
|
|
62
|
+
params: ["id"].freeze
|
|
63
|
+
}.freeze,
|
|
64
|
+
"update_target" => {
|
|
65
|
+
path: "/targets/{id}",
|
|
66
|
+
methods: ["PATCH"].freeze,
|
|
67
|
+
response: :json,
|
|
68
|
+
required: ["id"].freeze,
|
|
69
|
+
params: ["id", "paused", "muted", "seen"].freeze
|
|
70
|
+
}.freeze
|
|
71
|
+
}.freeze
|
|
72
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OhSpotted
|
|
4
|
+
# Base class for every SDK-defined error.
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
|
|
7
|
+
# The client configuration is missing or unusable.
|
|
8
|
+
class ConfigurationError < Error; end
|
|
9
|
+
|
|
10
|
+
# A request value cannot be represented safely on the wire.
|
|
11
|
+
class SerializationError < Error
|
|
12
|
+
attr_reader :param
|
|
13
|
+
|
|
14
|
+
def initialize(message, param = nil)
|
|
15
|
+
super(message)
|
|
16
|
+
@param = param
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The request failed before a complete HTTP response was received.
|
|
21
|
+
class TransportError < Error; end
|
|
22
|
+
|
|
23
|
+
# OhSpotted returned a non-success HTTP status.
|
|
24
|
+
class APIError < Error
|
|
25
|
+
# error_code is the API's error.code (e.g. "no_credits"), nil when the body has none.
|
|
26
|
+
attr_reader :status, :error_code, :error_message, :response_body, :raw_response
|
|
27
|
+
|
|
28
|
+
def initialize(raw_response:, response_body: nil, error_message: nil, error_code: nil)
|
|
29
|
+
super(error_message || "OhSpotted API request failed with status #{raw_response.status}.")
|
|
30
|
+
@status = raw_response.status
|
|
31
|
+
@error_code = error_code
|
|
32
|
+
@error_message = error_message
|
|
33
|
+
@response_body = response_body
|
|
34
|
+
@raw_response = raw_response
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# A successful response could not be decoded as the documented representation.
|
|
39
|
+
class ResponseDecodingError < Error
|
|
40
|
+
attr_reader :raw_response
|
|
41
|
+
|
|
42
|
+
def initialize(message, raw_response)
|
|
43
|
+
super(message)
|
|
44
|
+
@raw_response = raw_response
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated from the OhSpotted OpenAPI document. Do not edit by hand.
|
|
4
|
+
|
|
5
|
+
module OhSpotted
|
|
6
|
+
# One method per documented endpoint. Mixed into {Client}.
|
|
7
|
+
module Operations
|
|
8
|
+
# Follow a page. Adds a LinkedIn profile, company page or job to the list. The first read happens shortly after, usually within minutes, and only takes the starting picture: signals are what changes after it, once a day. Needs the credits of one read (2 fo…
|
|
9
|
+
#
|
|
10
|
+
# +POST /targets+
|
|
11
|
+
#
|
|
12
|
+
# @param url [String] (required) The page's LinkedIn address, as copied from a browser (with or without https and www)
|
|
13
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
14
|
+
# @return [JsonResponse]
|
|
15
|
+
def add_target(request_options: nil, **params)
|
|
16
|
+
call_operation("add_target", params, request_options)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Get a page you follow. One target, with its latest signal.
|
|
20
|
+
#
|
|
21
|
+
# +GET /targets/{id}+
|
|
22
|
+
#
|
|
23
|
+
# @param id [String] (required) id returned when the page was added
|
|
24
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
25
|
+
# @return [JsonResponse]
|
|
26
|
+
def get_target(request_options: nil, **params)
|
|
27
|
+
call_operation("get_target", params, request_options)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Get your plan and credits. The plan, the credits left, how many pages are followed and how many the plan allows, and the credits the active pages use in 30 days. Everything here uses the account's own list and credits, like the app: each page followed is read once a…
|
|
31
|
+
#
|
|
32
|
+
# +GET /usage+
|
|
33
|
+
#
|
|
34
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
35
|
+
# @return [JsonResponse]
|
|
36
|
+
def get_usage(request_options: nil, **params)
|
|
37
|
+
call_operation("get_usage", params, request_options)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Read what changed on all your pages. The signals found on every page of the list since each was added, newest first: the same as The Tea in the app.
|
|
41
|
+
#
|
|
42
|
+
# +GET /signals+
|
|
43
|
+
#
|
|
44
|
+
# @param limit [Integer] Signals returned, newest first
|
|
45
|
+
# @param unread [Integer] 1 (or true) for the signals not seen yet only; 0 (the default) for all of them
|
|
46
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
47
|
+
# @return [JsonResponse]
|
|
48
|
+
def list_signals(request_options: nil, **params)
|
|
49
|
+
call_operation("list_signals", params, request_options)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Read what changed on a page. The signals found on one page since the account added it, newest first. A signal is a change between two daily reads: nothing is found between them, and a change made and undone between two reads is never seen.
|
|
53
|
+
#
|
|
54
|
+
# +GET /targets/{id}/signals+
|
|
55
|
+
#
|
|
56
|
+
# @param id [String] (required) id returned when the page was added
|
|
57
|
+
# @param limit [Integer] Signals returned, newest first
|
|
58
|
+
# @param unread [Integer] 1 (or true) for the signals not seen yet only; 0 (the default) for all of them
|
|
59
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
60
|
+
# @return [JsonResponse]
|
|
61
|
+
def list_target_signals(request_options: nil, **params)
|
|
62
|
+
call_operation("list_target_signals", params, request_options)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# List the pages you follow. The account's list, newest first, with each page's state and its latest signal. A target is a LinkedIn profile, company page or job followed by the account. Send url to find out whether one LinkedIn page is on the list.
|
|
66
|
+
#
|
|
67
|
+
# +GET /targets+
|
|
68
|
+
#
|
|
69
|
+
# @param url [String] Only the target that follows this LinkedIn address (with or without https, www or tracking parameters): one item, or none when the page isn't on the list
|
|
70
|
+
# @param kind [String] Only this kind of page
|
|
71
|
+
# @param page [Integer] Page number
|
|
72
|
+
# @param limit [Integer] Targets per page
|
|
73
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
74
|
+
# @return [JsonResponse]
|
|
75
|
+
def list_targets(request_options: nil, **params)
|
|
76
|
+
call_operation("list_targets", params, request_options)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Mark everything as seen. Marks every signal found so far as seen, on every page of the list. No body is needed. For one page, send seen: true to PATCH /targets/{id}.
|
|
80
|
+
#
|
|
81
|
+
# +POST /signals/seen+
|
|
82
|
+
#
|
|
83
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
84
|
+
# @return [JsonResponse]
|
|
85
|
+
def mark_signals_seen(request_options: nil, **params)
|
|
86
|
+
call_operation("mark_signals_seen", params, request_options)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Stop following a page. Takes the page off the list. Its signals are no longer shown to the account; nothing else changes for the people who follow it too.
|
|
90
|
+
#
|
|
91
|
+
# +DELETE /targets/{id}+
|
|
92
|
+
#
|
|
93
|
+
# @param id [String] (required) id returned when the page was added
|
|
94
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
95
|
+
# @return [JsonResponse]
|
|
96
|
+
def remove_target(request_options: nil, **params)
|
|
97
|
+
call_operation("remove_target", params, request_options)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Pause, resume, mute or mark a page as seen. Send paused, muted and/or seen. A paused page isn't read and costs nothing; a muted page is still read and its signals are kept, but it isn't in the daily email. seen: true marks every signal found on the page so far as seen. A page paused…
|
|
101
|
+
#
|
|
102
|
+
# +PATCH /targets/{id}+
|
|
103
|
+
#
|
|
104
|
+
# @param id [String] (required) id returned when the page was added
|
|
105
|
+
# @param paused [Boolean] true to pause, false to resume
|
|
106
|
+
# @param muted [Boolean] true to leave it out of the email
|
|
107
|
+
# @param seen [Boolean] true to mark its signals as seen; false is refused
|
|
108
|
+
# @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
|
|
109
|
+
# @return [JsonResponse]
|
|
110
|
+
def update_target(request_options: nil, **params)
|
|
111
|
+
call_operation("update_target", params, request_options)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OhSpotted
|
|
4
|
+
# Buffered HTTP response: status, lower-cased multi-value headers, content type and body bytes.
|
|
5
|
+
RawResponse = Struct.new(:status, :headers, :content_type, :body, keyword_init: true)
|
|
6
|
+
|
|
7
|
+
# Outcome of one Client#batch item: +value+ when +ok?+, else +error+.
|
|
8
|
+
BatchResult = Struct.new(:index, :value, :error, keyword_init: true) do
|
|
9
|
+
def ok? = error.nil?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# A successful JSON response; +data+ is the parsed body (string keys).
|
|
13
|
+
class JsonResponse
|
|
14
|
+
attr_reader :data, :raw_response
|
|
15
|
+
|
|
16
|
+
def initialize(data:, raw_response:)
|
|
17
|
+
@data = data
|
|
18
|
+
@raw_response = raw_response
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def kind = :json
|
|
22
|
+
def json? = true
|
|
23
|
+
def binary? = false
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A successful non-JSON response (image, PDF, HTML…).
|
|
27
|
+
class BinaryResponse
|
|
28
|
+
attr_reader :bytes, :content_type, :raw_response
|
|
29
|
+
|
|
30
|
+
def initialize(bytes:, content_type:, raw_response:)
|
|
31
|
+
@bytes = bytes
|
|
32
|
+
@content_type = content_type
|
|
33
|
+
@raw_response = raw_response
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def kind = :binary
|
|
37
|
+
def json? = false
|
|
38
|
+
def binary? = true
|
|
39
|
+
|
|
40
|
+
# Writes the body to +path+ and returns the number of bytes written.
|
|
41
|
+
def save(path)
|
|
42
|
+
File.binwrite(path, bytes)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "uri"
|
|
5
|
+
|
|
6
|
+
module OhSpotted
|
|
7
|
+
# Request serialization: path filling, query pairs and JSON bodies.
|
|
8
|
+
module Serialization
|
|
9
|
+
QUERY_STRING_PARAMS = { "/products/{id}/check" => %w[wait] }.freeze
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
# Fills {name} path segments, then returns [path, query_pairs, body].
|
|
14
|
+
# nil values are omitted; false and 0 are sent.
|
|
15
|
+
def serialize(method, path_template, params)
|
|
16
|
+
raise SerializationError, "Request parameters must be a Hash." unless params.nil? || params.is_a?(Hash)
|
|
17
|
+
|
|
18
|
+
remaining = {}
|
|
19
|
+
(params || {}).each { |name, value| remaining[name.to_s] = value unless value.nil? }
|
|
20
|
+
path = path_template.gsub(/\{([^}]+)\}/) do
|
|
21
|
+
name = Regexp.last_match(1)
|
|
22
|
+
raise SerializationError.new("The \"#{name}\" path parameter is required.", name) unless remaining.key?(name)
|
|
23
|
+
|
|
24
|
+
URI.encode_www_form_component(wire_string(name, remaining.delete(name))).gsub("+", "%20")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if %w[POST PATCH].include?(method)
|
|
28
|
+
# The API reads wait from the query string on POST /products/{id}/check.
|
|
29
|
+
globals = QUERY_STRING_PARAMS.fetch(path_template, []).filter_map { |name| [name, wire_string(name, remaining.delete(name))] if remaining.key?(name) }
|
|
30
|
+
return [path, globals, remaining]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
pairs = []
|
|
34
|
+
remaining.each do |name, value|
|
|
35
|
+
if value.is_a?(Array)
|
|
36
|
+
value.each { |item| pairs << [name, wire_string(name, item)] unless item.nil? }
|
|
37
|
+
else
|
|
38
|
+
pairs << [name, wire_string(name, value)]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
[path, pairs, nil]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def wire_string(name, value)
|
|
45
|
+
case value
|
|
46
|
+
when String then value
|
|
47
|
+
when true, false, Integer, Symbol then value.to_s
|
|
48
|
+
when Float
|
|
49
|
+
raise SerializationError.new("The \"#{name}\" parameter must be a finite number.", name) unless value.finite?
|
|
50
|
+
|
|
51
|
+
value == value.floor ? value.to_i.to_s : value.to_s
|
|
52
|
+
when Hash, Array then JSON.generate(value)
|
|
53
|
+
else
|
|
54
|
+
raise SerializationError.new("The \"#{name}\" parameter has an unsupported type (#{value.class}).", name)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def encode_query(pairs)
|
|
59
|
+
pairs.map { |name, value| "#{escape(name)}=#{escape(value)}" }.join("&")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def escape(value)
|
|
63
|
+
URI.encode_www_form_component(value).gsub("+", "%20")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
|
|
6
|
+
module OhSpotted
|
|
7
|
+
# Default transport on Net::HTTP. A custom transport is any object with
|
|
8
|
+
# +call(method:, url:, headers:, body:, timeout:)+ returning +[status, headers, body]+,
|
|
9
|
+
# where headers is a Hash of lower-cased names to arrays of values.
|
|
10
|
+
class NetHTTPTransport
|
|
11
|
+
def call(method:, url:, headers:, body:, timeout:)
|
|
12
|
+
uri = URI(url)
|
|
13
|
+
request = Net::HTTP.const_get(method.capitalize).new(uri)
|
|
14
|
+
headers.each { |name, value| request[name] = value }
|
|
15
|
+
request.body = body if body
|
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
17
|
+
http.use_ssl = uri.scheme == "https"
|
|
18
|
+
if timeout
|
|
19
|
+
http.open_timeout = timeout
|
|
20
|
+
http.read_timeout = timeout
|
|
21
|
+
http.write_timeout = timeout
|
|
22
|
+
end
|
|
23
|
+
response = http.start { |connection| connection.request(request) }
|
|
24
|
+
[response.code.to_i, response.to_hash, response.body || ""]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/ohspotted.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "ohspotted/version"
|
|
4
|
+
require_relative "ohspotted/errors"
|
|
5
|
+
require_relative "ohspotted/responses"
|
|
6
|
+
require_relative "ohspotted/serialization"
|
|
7
|
+
require_relative "ohspotted/transport"
|
|
8
|
+
require_relative "ohspotted/endpoints"
|
|
9
|
+
require_relative "ohspotted/operations"
|
|
10
|
+
require_relative "ohspotted/client"
|
|
11
|
+
|
|
12
|
+
# Official Ruby SDK for the OhSpotted API (https://www.ohspotted.com).
|
|
13
|
+
module OhSpotted
|
|
14
|
+
end
|
data/sig/ohspotted.rbs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module OhSpotted
|
|
2
|
+
VERSION: String
|
|
3
|
+
ENDPOINTS: Hash[String, Hash[Symbol, untyped]]
|
|
4
|
+
|
|
5
|
+
class Error < StandardError
|
|
6
|
+
end
|
|
7
|
+
class ConfigurationError < Error
|
|
8
|
+
end
|
|
9
|
+
class SerializationError < Error
|
|
10
|
+
attr_reader param: String?
|
|
11
|
+
def initialize: (String message, ?String? param) -> void
|
|
12
|
+
end
|
|
13
|
+
class TransportError < Error
|
|
14
|
+
end
|
|
15
|
+
class APIError < Error
|
|
16
|
+
attr_reader status: Integer
|
|
17
|
+
attr_reader error_code: String?
|
|
18
|
+
attr_reader error_message: String?
|
|
19
|
+
attr_reader response_body: untyped
|
|
20
|
+
attr_reader raw_response: RawResponse
|
|
21
|
+
end
|
|
22
|
+
class ResponseDecodingError < Error
|
|
23
|
+
attr_reader raw_response: RawResponse
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class RawResponse < Struct[untyped]
|
|
27
|
+
attr_accessor status: Integer
|
|
28
|
+
attr_accessor headers: Hash[String, Array[String]]
|
|
29
|
+
attr_accessor content_type: String?
|
|
30
|
+
attr_accessor body: String
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class JsonResponse
|
|
34
|
+
attr_reader data: untyped
|
|
35
|
+
attr_reader raw_response: RawResponse
|
|
36
|
+
def kind: () -> :json
|
|
37
|
+
def json?: () -> true
|
|
38
|
+
def binary?: () -> false
|
|
39
|
+
end
|
|
40
|
+
class BinaryResponse
|
|
41
|
+
attr_reader bytes: String
|
|
42
|
+
attr_reader content_type: String?
|
|
43
|
+
attr_reader raw_response: RawResponse
|
|
44
|
+
def kind: () -> :binary
|
|
45
|
+
def json?: () -> false
|
|
46
|
+
def binary?: () -> true
|
|
47
|
+
def save: (String path) -> Integer
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class BatchResult < Struct[untyped]
|
|
51
|
+
attr_accessor index: Integer
|
|
52
|
+
attr_accessor value: untyped
|
|
53
|
+
attr_accessor error: StandardError?
|
|
54
|
+
def ok?: () -> bool
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
type response = JsonResponse | BinaryResponse
|
|
58
|
+
type request_options = { ?method: String, ?timeout: Numeric?, ?headers: Hash[String, String], ?max_retries: Integer }
|
|
59
|
+
|
|
60
|
+
module Operations
|
|
61
|
+
def add_target: (url: String, ?request_options: request_options?) -> JsonResponse
|
|
62
|
+
def get_target: (id: String, ?request_options: request_options?) -> JsonResponse
|
|
63
|
+
def get_usage: (?request_options: request_options?) -> JsonResponse
|
|
64
|
+
def list_signals: (?limit: Integer, ?unread: Integer, ?request_options: request_options?) -> JsonResponse
|
|
65
|
+
def list_target_signals: (id: String, ?limit: Integer, ?unread: Integer, ?request_options: request_options?) -> JsonResponse
|
|
66
|
+
def list_targets: (?url: String, ?kind: String, ?page: Integer, ?limit: Integer, ?request_options: request_options?) -> JsonResponse
|
|
67
|
+
def mark_signals_seen: (?request_options: request_options?) -> JsonResponse
|
|
68
|
+
def remove_target: (id: String, ?request_options: request_options?) -> JsonResponse
|
|
69
|
+
def update_target: (id: String, ?paused: bool, ?muted: bool, ?seen: bool, ?request_options: request_options?) -> JsonResponse
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
class Client
|
|
73
|
+
include Operations
|
|
74
|
+
DEFAULT_CONCURRENCY: Integer
|
|
75
|
+
MAX_RETRIES: Integer
|
|
76
|
+
RETRY_BACKOFF_FACTOR: Float
|
|
77
|
+
DEFAULT_RETRY_DELAY: Float
|
|
78
|
+
DEFAULT_TIMEOUT: Integer
|
|
79
|
+
def initialize: (?api_key: String?, ?base_url: String, ?timeout: Numeric?, ?headers: Hash[untyped, untyped], ?max_retries: Integer, ?retry_delay: Numeric, ?transport: untyped) -> void
|
|
80
|
+
def request: (String | Symbol method, String path, ?Hash[untyped, untyped]? params, ?timeout: Numeric?, ?headers: Hash[untyped, untyped]?, ?max_retries: Integer?) -> response
|
|
81
|
+
def batch: [I, T] (Enumerable[I] items, ?concurrency: Integer) { (I item) -> T } -> Array[BatchResult]
|
|
82
|
+
end
|
|
83
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ohspotted
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- OhSpotted
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-12-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Follow public LinkedIn profiles, company pages and jobs, and read what
|
|
14
|
+
changed on them as signals, checked once a day.
|
|
15
|
+
email:
|
|
16
|
+
- contact@ohspotted.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- examples/README.md
|
|
24
|
+
- examples/json.rb
|
|
25
|
+
- examples/request.rb
|
|
26
|
+
- lib/ohspotted.rb
|
|
27
|
+
- lib/ohspotted/client.rb
|
|
28
|
+
- lib/ohspotted/endpoints.rb
|
|
29
|
+
- lib/ohspotted/errors.rb
|
|
30
|
+
- lib/ohspotted/operations.rb
|
|
31
|
+
- lib/ohspotted/responses.rb
|
|
32
|
+
- lib/ohspotted/serialization.rb
|
|
33
|
+
- lib/ohspotted/transport.rb
|
|
34
|
+
- lib/ohspotted/version.rb
|
|
35
|
+
- sig/ohspotted.rbs
|
|
36
|
+
homepage: https://www.ohspotted.com
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata:
|
|
40
|
+
bug_tracker_uri: https://github.com/ohspotted/ohspotted-ruby/issues
|
|
41
|
+
documentation_uri: https://www.ohspotted.com/docs
|
|
42
|
+
homepage_uri: https://www.ohspotted.com
|
|
43
|
+
rubygems_mfa_required: 'true'
|
|
44
|
+
source_code_uri: https://github.com/ohspotted/ohspotted-ruby
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '3.1'
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
requirements: []
|
|
60
|
+
rubygems_version: 3.5.22
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 4
|
|
63
|
+
summary: Official Ruby SDK for the OhSpotted LinkedIn change tracking API.
|
|
64
|
+
test_files: []
|