postproxy-sdk 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 822ce030b347645daad188e55da76ab9a3494b0f7f01d0b6a78a02b4c9e933d6
4
- data.tar.gz: 33dc5d8cf8e97817b9f6f69d8f57dd4dfd207ff1b8add0ba58661cddfd88f64f
3
+ metadata.gz: a9a60fab0c383896df7be59f688fb8692ab12eb60725d031fac50e76d7acc507
4
+ data.tar.gz: 38cc6ceda7bb03d4adb4e2bdfe7a27155ee0d4ef20b39d6d2b82d8e115284201
5
5
  SHA512:
6
- metadata.gz: 8460f568b415ec00973fa57d9065a85a141fe16aafb430765054ae51ca0ee16c514a55c02f59c54b7983def183c9131c07c65a5db448976f05d9db2139243915
7
- data.tar.gz: 64c079b04bbd82dde18a2c612000ad42f8525351326714243c923dfde21bba6e51125006169a36675301b2fde2857f94c54e74cab08ae406345bf1dd8a26e711
6
+ metadata.gz: b314e1009d278281897233d3059b3a04c29d2729a86d9f06299113d11cb973788b01a29bb9393e5ac8e9bf62a08f63e9de35eabcc8a033e943350d774236c24c
7
+ data.tar.gz: c2142242f1ee28e96152c6de5869aca4821de27f6eb7b756c05034d2546d80a941fa0fd530ec823b6d6b1fde5e9b77f88aecc6503998d5bd143dbdc54e8fca09
data/README.md CHANGED
@@ -96,6 +96,56 @@ post = client.posts.create(
96
96
  client.posts.delete("post-id")
97
97
  ```
98
98
 
99
+ ## Post Stats
100
+
101
+ Retrieve stats snapshots for posts over time. Supports filtering by profiles/networks and timespan.
102
+
103
+ ```ruby
104
+ # Get stats for one or more posts
105
+ stats = client.posts.stats(["post-id-1", "post-id-2"])
106
+ stats.data.each do |post_id, post_stats|
107
+ post_stats.platforms.each do |platform|
108
+ puts "#{post_id} on #{platform.platform} (#{platform.profile_id}):"
109
+ platform.records.each do |record|
110
+ puts " #{record.recorded_at}: #{record.stats}"
111
+ end
112
+ end
113
+ end
114
+
115
+ # Filter by profiles or networks
116
+ stats = client.posts.stats(["post-id"], profiles: ["instagram", "twitter"])
117
+
118
+ # Filter by profile hashids
119
+ stats = client.posts.stats(["post-id"], profiles: ["prof-abc", "prof-def"])
120
+
121
+ # Filter by time range
122
+ stats = client.posts.stats(
123
+ ["post-id"],
124
+ from: "2026-02-01T00:00:00Z",
125
+ to: "2026-02-24T00:00:00Z"
126
+ )
127
+
128
+ # Using Time objects
129
+ stats = client.posts.stats(
130
+ ["post-id"],
131
+ from: Time.now - 86400 * 7,
132
+ to: Time.now
133
+ )
134
+ ```
135
+
136
+ Stats vary by platform:
137
+
138
+ | Platform | Fields |
139
+ |----------|--------|
140
+ | Instagram | `impressions`, `likes`, `comments`, `saved`, `profile_visits`, `follows` |
141
+ | Facebook | `impressions`, `clicks`, `likes` |
142
+ | Threads | `impressions`, `likes`, `replies`, `reposts`, `quotes`, `shares` |
143
+ | Twitter | `impressions`, `likes`, `retweets`, `comments`, `quotes`, `saved` |
144
+ | YouTube | `impressions`, `likes`, `comments`, `saved` |
145
+ | LinkedIn | `impressions` |
146
+ | TikTok | `impressions`, `likes`, `comments`, `shares` |
147
+ | Pinterest | `impressions`, `likes`, `comments`, `saved`, `outbound_clicks` |
148
+
99
149
  ## Profiles
100
150
 
101
151
  ```ruby
@@ -87,6 +87,19 @@ module PostProxy
87
87
  Post.new(**result)
88
88
  end
89
89
 
90
+ def stats(post_ids, profiles: nil, from: nil, to: nil)
91
+ params = { post_ids: post_ids.is_a?(Array) ? post_ids.join(",") : post_ids }
92
+ params[:profiles] = profiles.is_a?(Array) ? profiles.join(",") : profiles if profiles
93
+ params[:from] = format_time(from) if from
94
+ params[:to] = format_time(to) if to
95
+
96
+ result = @client.request(:get, "/posts/stats", params: params)
97
+ posts = (result[:data] || {}).each_with_object({}) do |(post_id, post_data), hash|
98
+ hash[post_id.to_s] = PostStats.new(**post_data.transform_keys(&:to_sym))
99
+ end
100
+ StatsResponse.new(data: posts)
101
+ end
102
+
90
103
  def delete(id, profile_group_id: nil)
91
104
  result = @client.request(:delete, "/posts/#{id}", profile_group_id: profile_group_id)
92
105
  DeleteResponse.new(**result)
@@ -110,6 +110,56 @@ module PostProxy
110
110
  attr_accessor :id, :name
111
111
  end
112
112
 
113
+ class StatsRecord < Model
114
+ attr_accessor :stats, :recorded_at
115
+
116
+ def initialize(**attrs)
117
+ @stats = {}
118
+ @recorded_at = nil
119
+ super
120
+ @recorded_at = parse_time(@recorded_at)
121
+ end
122
+
123
+ private
124
+
125
+ def parse_time(value)
126
+ return nil if value.nil?
127
+ value.is_a?(Time) ? value : Time.parse(value.to_s)
128
+ end
129
+ end
130
+
131
+ class PlatformStats < Model
132
+ attr_accessor :profile_id, :platform, :records
133
+
134
+ def initialize(**attrs)
135
+ @records = []
136
+ super
137
+ @records = (@records || []).map do |r|
138
+ r.is_a?(StatsRecord) ? r : StatsRecord.new(**r.transform_keys(&:to_sym))
139
+ end
140
+ end
141
+ end
142
+
143
+ class PostStats < Model
144
+ attr_accessor :platforms
145
+
146
+ def initialize(**attrs)
147
+ @platforms = []
148
+ super
149
+ @platforms = (@platforms || []).map do |p|
150
+ p.is_a?(PlatformStats) ? p : PlatformStats.new(**p.transform_keys(&:to_sym))
151
+ end
152
+ end
153
+ end
154
+
155
+ class StatsResponse
156
+ attr_reader :data
157
+
158
+ def initialize(data:)
159
+ @data = data
160
+ end
161
+ end
162
+
113
163
  class ListResponse
114
164
  attr_reader :data
115
165
 
@@ -1,3 +1,3 @@
1
1
  module PostProxy
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postproxy-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PostProxy