spooked 0.0.1
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/CHANGELOG.md +11 -0
- data/README.md +85 -0
- data/lib/spooked/api/base.rb +15 -0
- data/lib/spooked/api/posts.rb +27 -0
- data/lib/spooked/api.rb +10 -0
- data/lib/spooked/client.rb +86 -0
- data/lib/spooked.rb +10 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 04598c9e0c15534480b494465ef37e4e15308af7
|
4
|
+
data.tar.gz: 21ef933d6a027dca2c02d092a66cfd934831a6cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2da226760388f6592d4fb9a323308d46e7724824da0ae40e45151c42f40c0df99ec0fc038afada49cfb60647c5d3f25d10364816a81dab100e7a266eff53ea67
|
7
|
+
data.tar.gz: 9deacc3b55431e4b536f139f9ae9e7e7c4260c93bb8fde635ab7f7ae1d4a8cd43a15575b1c66ec5b89ee37557a8f20813797c8c9bec02df452f48e528ca4f222
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# spooked Changelog
|
2
|
+
|
3
|
+
An experimental (and very limited!) unofficial Ruby client for the
|
4
|
+
[ghost.org / ghost.io blogging platform API](http://api.ghost.org/).
|
5
|
+
|
6
|
+
## v0
|
7
|
+
|
8
|
+
### v0.0.1 (2016-12-02)
|
9
|
+
|
10
|
+
- Initial Client version
|
11
|
+
- Initial Post.list support
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# spooked
|
2
|
+
|
3
|
+
An experimental (and very limited!) unofficial Ruby client for the
|
4
|
+
[ghost.org / ghost.io blogging platform API](http://api.ghost.org/).
|
5
|
+
|
6
|
+
[](https://badge.fury.io/rb/spooked)
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
### Client Options
|
11
|
+
|
12
|
+
If not explicitly passed a client, all methods will fall back to
|
13
|
+
`Client.default_client`. You can set that default client directly or
|
14
|
+
have it auto-constructed from a set of default options:
|
15
|
+
|
16
|
+
#### access_token
|
17
|
+
|
18
|
+
**Has no default, must be provided.**
|
19
|
+
|
20
|
+
Your User Authentication Bearer Token. See
|
21
|
+
http://api.ghost.org/docs/user-authentication for details on how to obtain that
|
22
|
+
token.
|
23
|
+
|
24
|
+
#### connection_builder
|
25
|
+
|
26
|
+
**Optional**
|
27
|
+
|
28
|
+
A Faraday connection builder. Defaults to:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
->(builder) {
|
32
|
+
builder.adapter Faraday.default_adapter
|
33
|
+
builder.request :url_encoded
|
34
|
+
builder.response :parse_json
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
#### connection_options
|
39
|
+
|
40
|
+
**Optional**
|
41
|
+
|
42
|
+
A `Hash` of options passed as the second parameter to
|
43
|
+
`Faraday::Connection.new`.
|
44
|
+
|
45
|
+
#### subdomain
|
46
|
+
|
47
|
+
**Has no default, optional**
|
48
|
+
|
49
|
+
For ghost.io hosted ghost instances, set this to your ghost.io subdomain, i.e.
|
50
|
+
the word preceding `ghost.io` in the URL of your blog's administration
|
51
|
+
interface.
|
52
|
+
|
53
|
+
For self-hosted instances, you probably want to keep the `subdomain` empty and
|
54
|
+
overwrite `url_base` instead.
|
55
|
+
|
56
|
+
#### url_base
|
57
|
+
|
58
|
+
**Optional**
|
59
|
+
|
60
|
+
Defaults to `->(client) { "https://#{client.subdomain}.ghost.io/ghost/api/v0.1" }`.
|
61
|
+
You should generally only overwrite this if you self-host your ghost instance.
|
62
|
+
|
63
|
+
### APIs
|
64
|
+
|
65
|
+
- `Posts.list(fields: nil, filter: nil, include: nil, limit: 15, order: "published_at desc", page: 1)`
|
66
|
+
|
67
|
+
### Response format
|
68
|
+
|
69
|
+
All responses are returned as a `Hash` with all keys and values exactly
|
70
|
+
as described in the [API Reference Documentation](http://api.ghost.org/docs).
|
71
|
+
|
72
|
+
## Compatibility
|
73
|
+
|
74
|
+
So far, this has only been verified to work on Ruby (MRI) 2.3.3. I have
|
75
|
+
no plans to support any Ruby versions below 2.3.
|
76
|
+
|
77
|
+
## Status
|
78
|
+
|
79
|
+
This library is in a very early stage, only supports a very limited subset of
|
80
|
+
the API and further e.g. does not yet feature any automated tests, nor does it
|
81
|
+
significantly transform any API responses, provide convenience helpers, etc.
|
82
|
+
|
83
|
+
At the moment, The following APIs are supported:
|
84
|
+
|
85
|
+
- [GET /posts/](http://api.ghost.org/docs/posts)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spooked
|
4
|
+
module API
|
5
|
+
class Posts < Base
|
6
|
+
class << self
|
7
|
+
def list(
|
8
|
+
fields: nil,
|
9
|
+
filter: nil,
|
10
|
+
include_: nil, # include is a reserved keyword
|
11
|
+
limit: 15,
|
12
|
+
order: "published_at desc",
|
13
|
+
page: 1
|
14
|
+
)
|
15
|
+
client.get("posts/", { params: {
|
16
|
+
fields: fields,
|
17
|
+
filter: filter,
|
18
|
+
include: include_,
|
19
|
+
limit: limit,
|
20
|
+
order: order,
|
21
|
+
page: page,
|
22
|
+
}.reject { |k, v| v.nil? } })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/spooked/api.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spooked
|
4
|
+
class Client
|
5
|
+
OPTIONS_WITH_CLASS_DEFAULT = [
|
6
|
+
:access_token,
|
7
|
+
:connection_builder,
|
8
|
+
:connection_options,
|
9
|
+
:subdomain,
|
10
|
+
:url_base,
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
OPTIONS_WITH_CLASS_DEFAULT.each do |option|
|
14
|
+
define_singleton_method(option) do
|
15
|
+
instance_variable_get("@#{option}")
|
16
|
+
end
|
17
|
+
|
18
|
+
define_singleton_method("#{option}=") do |*args|
|
19
|
+
instance_variable_set("@#{option}", *args)
|
20
|
+
end
|
21
|
+
|
22
|
+
define_method(option) do
|
23
|
+
instance_variable_get("@#{option}")
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method("#{option}=") do |*args|
|
27
|
+
instance_variable_set("@#{option}", *args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
self.connection_builder = ->(builder) {
|
32
|
+
builder.adapter Faraday.default_adapter
|
33
|
+
builder.request :url_encoded
|
34
|
+
builder.response :json
|
35
|
+
}
|
36
|
+
|
37
|
+
self.connection_options = {}
|
38
|
+
|
39
|
+
self.url_base = ->(client) {
|
40
|
+
"https://#{subdomain}.ghost.io/ghost/api/v0.1"
|
41
|
+
}
|
42
|
+
|
43
|
+
[
|
44
|
+
:delete,
|
45
|
+
:get,
|
46
|
+
:post,
|
47
|
+
:put,
|
48
|
+
].each do |http_verb|
|
49
|
+
define_method(http_verb) do |*args|
|
50
|
+
connection.public_send(http_verb, *args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize(**options)
|
55
|
+
unknown_options = options.keys - OPTIONS_WITH_CLASS_DEFAULT
|
56
|
+
raise ArgumentError, "Unknown option key(s): #{unknown_options.join(", ")}. Valid options are: #{OPTIONS_WITH_CLASS_DEFAULT.join(", ")}." if unknown_options.any?
|
57
|
+
|
58
|
+
OPTIONS_WITH_CLASS_DEFAULT.each do |option|
|
59
|
+
value = options[option].nil? ? self.class.public_send(option) : options[option]
|
60
|
+
public_send("#{option}=", value)
|
61
|
+
end
|
62
|
+
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def connection
|
69
|
+
@connection ||= Faraday::Connection.new(evaluate_option(url_base), params: { access_token: access_token }, &connection_builder)
|
70
|
+
end
|
71
|
+
|
72
|
+
def evaluate_option(option)
|
73
|
+
option.is_a?(Proc) ? instance_eval(&option) : option
|
74
|
+
end
|
75
|
+
|
76
|
+
class << self
|
77
|
+
def default_client
|
78
|
+
@default_client ||= new
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_client=(client)
|
82
|
+
@default_client = client
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/spooked.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spooked
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Niels Ganser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-02 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.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.10'
|
41
|
+
description:
|
42
|
+
email: niels@herimedia.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- CHANGELOG.md
|
47
|
+
- README.md
|
48
|
+
files:
|
49
|
+
- CHANGELOG.md
|
50
|
+
- README.md
|
51
|
+
- lib/spooked.rb
|
52
|
+
- lib/spooked/api.rb
|
53
|
+
- lib/spooked/api/base.rb
|
54
|
+
- lib/spooked/api/posts.rb
|
55
|
+
- lib/spooked/client.rb
|
56
|
+
homepage: https://github.com/herimedia/spooked
|
57
|
+
licenses:
|
58
|
+
- Apache-2.0
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.5.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: An experimental unofficial API client for the ghost.org blogging platform
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|