threads-api 0.1.0 → 0.2.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 +4 -4
- data/README.md +11 -1
- data/lib/threads/api/client.rb +37 -3
- data/lib/threads/api/profile.rb +18 -0
- data/lib/threads/api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 422f4c1e70e0a2d5402d70646e6afd8fc095ff070b65e59f0acbf0afe4e66127
|
4
|
+
data.tar.gz: 421de26fc580b70c9bb76b4ef08adf040c97f94e92a7666acde6c42cbf9b1098
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56d8bc23aa227e36406e1446159b13ea22317ea763dadb22aa25e07b17d7ae40eed568b16c614544035d33be72bb747af512a9ede63ad7fe4a03955fe7aab894
|
7
|
+
data.tar.gz: 6d1350e527061f18955d7cf4744a97e27ca5fcf65b3fc9515bdce8d7a18fe65e59f400a950e1023f251b295c8d2e68d986b6193e257a235e89d960c01c8316c9
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ thread = client.get_thread("18050206876707110", user_id: "7770386109746442")
|
|
76
76
|
`Threads::API::Client#list_threads` accepts the following options:
|
77
77
|
|
78
78
|
* `user_id` - The ID of the user whose threads you want to read. Defaults to `"me"`, the authenticated user.
|
79
|
-
* `fields` - An Array (or comma-separated String) of fields to include in the response. By default,
|
79
|
+
* `fields` - An Array (or comma-separated String) of fields to include in the response. By default, all documented fields are requested. See the [Threads API documentation](https://developers.facebook.com/docs/threads/threads-media#fields) for a list of available fields.
|
80
80
|
* `since` - An ISO 8601 date string. Only threads published after this date will be returned.
|
81
81
|
* `until` - An ISO 8601 date string. Only threads published before this date will be returned.
|
82
82
|
* `before` - A cursor string returned by a previous request for pagination.
|
@@ -85,6 +85,16 @@ thread = client.get_thread("18050206876707110", user_id: "7770386109746442")
|
|
85
85
|
|
86
86
|
`Threads::API::Client#get_thread` accepts only the `user_id` and `fields` options.
|
87
87
|
|
88
|
+
## Reading profiles
|
89
|
+
|
90
|
+
To get a user's profile:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
profile = client.get_profile("7770386109746442")
|
94
|
+
```
|
95
|
+
|
96
|
+
`Threads::API::Client#get_profile` accepts a `fields` option, which is an Array (or comma-separated String) of fields to include in the response. By default, all documented fields are requested. See the [Threads API documentation](https://developers.facebook.com/docs/threads/threads-profiles#fields) for a list of available fields.
|
97
|
+
|
88
98
|
## Posting to Threads
|
89
99
|
|
90
100
|
Posting to Threads is, at the very least, a two-step process. Threads requires that you first create a container for the media you want to post, then explicitly publishing that container as a thread. However, more steps are involved if you want to post multiple media items in a single thread.
|
data/lib/threads/api/client.rb
CHANGED
@@ -1,17 +1,49 @@
|
|
1
|
+
require_relative "profile"
|
1
2
|
require_relative "thread"
|
2
3
|
|
3
4
|
module Threads
|
4
5
|
module API
|
5
6
|
class Client
|
7
|
+
PROFILE_FIELDS = %w[id username threads_profile_picture_url threads_biography]
|
8
|
+
POST_FIELDS = %w[
|
9
|
+
id
|
10
|
+
media_product_type
|
11
|
+
media_type
|
12
|
+
media_url
|
13
|
+
permalink
|
14
|
+
owner
|
15
|
+
username
|
16
|
+
text
|
17
|
+
timestamp
|
18
|
+
shortcode
|
19
|
+
thumbnail_url
|
20
|
+
children
|
21
|
+
is_quote_post
|
22
|
+
]
|
23
|
+
|
6
24
|
def initialize(access_token)
|
7
25
|
@access_token = access_token
|
8
26
|
end
|
9
27
|
|
28
|
+
def get_profile(user_id = "me", fields: PROFILE_FIELDS)
|
29
|
+
params = {access_token: @access_token}
|
30
|
+
params[:fields] = Array(fields).join(",") if fields
|
31
|
+
|
32
|
+
response = connection.get(user_id, params)
|
33
|
+
|
34
|
+
Threads::API::Profile.new(response.body)
|
35
|
+
end
|
36
|
+
|
10
37
|
def list_threads(user_id: "me", **options)
|
11
38
|
params = options.slice(:since, :until, :before, :after, :limit).compact
|
12
39
|
params[:access_token] = @access_token
|
13
40
|
|
14
|
-
fields =
|
41
|
+
fields = if options.key?(:fields)
|
42
|
+
Array(options[:fields]).join(",")
|
43
|
+
else
|
44
|
+
POST_FIELDS.join(",")
|
45
|
+
end
|
46
|
+
|
15
47
|
params[:fields] = fields unless fields.empty?
|
16
48
|
|
17
49
|
response = connection.get("#{user_id}/threads", params)
|
@@ -19,7 +51,7 @@ module Threads
|
|
19
51
|
Threads::API::Thread::List.new(response.body)
|
20
52
|
end
|
21
53
|
|
22
|
-
def get_thread(thread_id, fields:
|
54
|
+
def get_thread(thread_id, fields: POST_FIELDS)
|
23
55
|
params = {access_token: @access_token}
|
24
56
|
params[:fields] = Array(fields).join(",") if fields
|
25
57
|
|
@@ -75,9 +107,11 @@ module Threads
|
|
75
107
|
Threads::API::UnpublishedThread.new(response.body)
|
76
108
|
end
|
77
109
|
|
78
|
-
def create_carousel_thread(children:, text: nil)
|
110
|
+
def create_carousel_thread(children:, text: nil, reply_to_id: nil, reply_control: nil)
|
79
111
|
params = {access_token: @access_token, media_type: "CAROUSEL", text: text}
|
80
112
|
params[:children] = Array(children).join(",")
|
113
|
+
params[:reply_to_id] = reply_to_id if reply_to_id
|
114
|
+
params[:reply_control] = reply_control if reply_control
|
81
115
|
|
82
116
|
raise ArgumentError, "At least one item must be present in the `:children` option" if params[:children].empty?
|
83
117
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "time"
|
2
|
+
|
3
|
+
module Threads
|
4
|
+
module API
|
5
|
+
class Profile
|
6
|
+
attr_reader :id, :username, :profile_picture_url, :biography
|
7
|
+
|
8
|
+
def initialize(json)
|
9
|
+
@id = json["id"]
|
10
|
+
@username = json["username"]
|
11
|
+
@profile_picture_url = json["profile_picture_url"]
|
12
|
+
@biography = json["biography"]
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :bio, :biography
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/threads/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threads-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/threads/api.rb
|
40
40
|
- lib/threads/api/client.rb
|
41
41
|
- lib/threads/api/oauth2/client.rb
|
42
|
+
- lib/threads/api/profile.rb
|
42
43
|
- lib/threads/api/thread.rb
|
43
44
|
- lib/threads/api/version.rb
|
44
45
|
homepage: https://github.com/davidcelis/threads-api
|