orbit_activities 0.1.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc19e521a7103168771b57342dabb7bceffb4a051a52458102cd2c159d8e1ba4
4
- data.tar.gz: f1dccee34992a1c77528bd1d83a07aee16c728f9341a57f134d7d981e8ab52bc
3
+ metadata.gz: f1a41acb3a0bbbe16e86bf6b1c0d369207120f15085fb178015733f6cba8b353
4
+ data.tar.gz: d68d8d88b2d610b6f1b3e780ef52aa05381adbf087472479b10f87dad099c133
5
5
  SHA512:
6
- metadata.gz: 80a6d164b1352cc746168545e1d3a6c4f55097da810ec867e6540c455edfdacfa4dce9dc2843c52ae7b37a32b79a72f3c9f143d1031835f1cfe11ca35d468540
7
- data.tar.gz: 3e0f3ccba92e0fc6d404bb46f1a72f1c3177b5f9609adf465b5388adcf5ea0877c883a430efbd392eb93fab442d91205b10fb50b38e91df5cd30c06716ed2ad1
6
+ metadata.gz: 8f8b24a3552058ccd69b4d74ca073231b81803a50e742cd55c2bcded567169653031cf9f456ee2365791b63643d10ac64348516184182097164e89120a31d6d4
7
+ data.tar.gz: f04486582e0457c0f636a27224e9fbfe061a6748203bf07522ea9d0ff8a03813dbb59fe382b0ea21173becb4b43fea8072e8935436be4b4390e2900b786d3cf0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orbit_activities (0.0.2)
4
+ orbit_activities (0.2.2)
5
5
  http (~> 4.4)
6
6
  json (~> 2.5)
7
7
  rake (~> 13.0)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.7.0)
13
+ addressable (2.8.0)
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
15
  ast (2.4.2)
16
16
  byebug (11.1.3)
@@ -19,7 +19,7 @@ GEM
19
19
  diff-lcs (1.4.4)
20
20
  domain_name (0.5.20190701)
21
21
  unf (>= 0.0.5, < 1.0.0)
22
- ffi (1.15.0)
22
+ ffi (1.15.3)
23
23
  ffi-compiler (1.0.1)
24
24
  ffi (>= 1.0.0)
25
25
  rake
@@ -29,7 +29,7 @@ GEM
29
29
  http-cookie (~> 1.0)
30
30
  http-form_data (~> 2.2)
31
31
  http-parser (~> 1.2.0)
32
- http-cookie (1.0.3)
32
+ http-cookie (1.0.4)
33
33
  domain_name (~> 0.5)
34
34
  http-form_data (2.3.0)
35
35
  http-parser (1.2.3)
@@ -56,23 +56,23 @@ GEM
56
56
  diff-lcs (>= 1.2.0, < 2.0)
57
57
  rspec-support (~> 3.10.0)
58
58
  rspec-support (3.10.2)
59
- rubocop (1.14.0)
59
+ rubocop (1.17.0)
60
60
  parallel (~> 1.10)
61
61
  parser (>= 3.0.0.0)
62
62
  rainbow (>= 2.2.2, < 4.0)
63
63
  regexp_parser (>= 1.8, < 3.0)
64
64
  rexml
65
- rubocop-ast (>= 1.5.0, < 2.0)
65
+ rubocop-ast (>= 1.7.0, < 2.0)
66
66
  ruby-progressbar (~> 1.7)
67
67
  unicode-display_width (>= 1.4.0, < 3.0)
68
- rubocop-ast (1.5.0)
68
+ rubocop-ast (1.7.0)
69
69
  parser (>= 3.0.1.1)
70
70
  ruby-progressbar (1.11.0)
71
71
  unf (0.1.4)
72
72
  unf_ext
73
73
  unf_ext (0.0.7.7)
74
74
  unicode-display_width (2.0.0)
75
- webmock (3.12.2)
75
+ webmock (3.13.0)
76
76
  addressable (>= 2.3.6)
77
77
  crack (>= 0.3.2)
78
78
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -80,6 +80,7 @@ GEM
80
80
 
81
81
  PLATFORMS
82
82
  arm64-darwin-20
83
+ x86_64-linux
83
84
 
84
85
  DEPENDENCIES
85
86
  byebug
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # Orbit API Create Custom Activities Helper
1
+ # Orbit Activities Helper Library for Ruby
2
2
 
3
3
  ![Build Status](https://github.com/orbit-love/ruby-orbit-activities/workflows/CI/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/orbit_activities.svg)](https://badge.fury.io/rb/orbit_activities)
5
5
  [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](code_of_conduct.md)
6
6
 
7
- > This is a Ruby gem that can be included in any Ruby application to take care of the logic of interacting with the Orbit API to create custom activities.
7
+ > Orbit API helper library for Ruby. <br>This client can create, read, update and delete activities in your Orbit workspace.
8
8
 
9
- <hr />
9
+ <img src="https://github.com/orbit-love/js-orbit-activities/blob/bc4ce38a34af95e40b2c3e54ba44d3df6b3d3aac/.github/logo.png" alt="Orbit" style="max-width: 300px; margin: 2em 0;">
10
10
 
11
11
  ## Package Usage
12
12
 
@@ -20,19 +20,105 @@ gem "orbit_activities"
20
20
 
21
21
  Then, run `bundle install` from your terminal.
22
22
 
23
- ### Send Custom Activity
23
+ ### Usage
24
24
 
25
- To send a custom activity to Orbit using the gem, instantiate a new instance of the `Request` class:
25
+ #### Create an Activity
26
+
27
+ To create an activity:
28
+
29
+ ```ruby
30
+ OrbitActivities::Request.new(
31
+ api_key: # Your Orbit API key,
32
+ workspace_id: # Your Orbit workspace ID,
33
+ action: "new_activity",
34
+ body: # The custom activity object in JSON format, see Orbit API docs for reference
35
+ )
36
+ ```
37
+
38
+ You can inspect the Orbit API response by appending `.response` to the end of the initialization method.
39
+ #### Update an Activity
40
+
41
+ To update an activity:
42
+
43
+ ```ruby
44
+ OrbitActivities::Request.new(
45
+ api_key: # Your Orbit API key,
46
+ workspace_id: # Your Orbit workspace ID,
47
+ action: "update_activity",
48
+ activity_id: # The ID of the activity to be updated,
49
+ member_id: # The ID of the member the activity is attached to,
50
+ body: # The custom activity object in JSON format, see Orbit API docs for reference
51
+ )
52
+ ```
53
+
54
+ You can inspect the Orbit API response by appending `.response` to the end of the initialization method.
55
+ #### Delete an Activity
56
+
57
+ To delete an activity:
26
58
 
27
59
  ```ruby
28
60
  OrbitActivities::Request.new(
29
61
  api_key: # Your Orbit API key,
30
62
  workspace_id: # Your Orbit workspace ID,
31
- body: # The custom activity object in JSON format
63
+ action: "delete_activity",
64
+ activity_id: # The ID of the activity to be updated,
65
+ member_id: # The ID of the member the activity is attached to
32
66
  )
33
67
  ```
34
68
 
35
- For details on the data structure the Orbit API expects for a custom activity object, refer to the [Orbit API Documentation](https://docs.orbit.love/reference#post_-workspace-id-activities).
69
+ You can inspect the Orbit API response by appending `.response` to the end of the initialization method.
70
+ #### List Activities
71
+
72
+ To list activities:
73
+
74
+ ```ruby
75
+ OrbitActivities::Request.new(
76
+ api_key: # Your Orbit API key,
77
+ workspace_id: # Your Orbit workspace ID,
78
+ action: "list_activities",
79
+ filters: # Any filters on the request in JSON format, see Orbit API docs for reference
80
+ ).response
81
+ ```
82
+ #### Get Specific Activity
83
+
84
+ To get a specific activity:
85
+
86
+ ```ruby
87
+ OrbitActivities::Request.new(
88
+ api_key: # Your Orbit API key,
89
+ workspace_id: # Your Orbit workspace ID,
90
+ action: "get_activity",
91
+ activity_id: # The ID of the actiivity
92
+ ).response
93
+ ```
94
+ #### Get Member Activities
95
+
96
+ To get activities associated with a specific member:
97
+
98
+ ```ruby
99
+ OrbitActivities::Request.new(
100
+ api_key: # Your Orbit API key,
101
+ workspace_id: # Your Orbit workspace ID,
102
+ action: "list_member_activities",
103
+ activity_id: # The ID of the actiivity,
104
+ member_id: # The ID of the member,
105
+ filters: # Any filters on the request in JSON format, see Orbit API docs for reference
106
+ ).response
107
+ ```
108
+ #### Get Latest Activity Timestamp for Activity Type
109
+
110
+ To get the latest activity timestamp for a specific activity type:
111
+
112
+ ```ruby
113
+ OrbitActivities::Request.new(
114
+ api_key: # Your Orbit API key,
115
+ workspace_id: # Your Orbit workspace ID,
116
+ action: "latest_activity_timestamp",
117
+ filters: { activity_type: # Activity type to search for, e.g. "custom:linkedin:comment" }
118
+ ).response
119
+ ```
120
+
121
+ For details on the data structures the Orbit API expects, refer to the [Orbit API Documentation](https://docs.orbit.love/reference).
36
122
 
37
123
  ## Contributing
38
124
 
@@ -44,4 +130,4 @@ This is available as open source under the terms of the [MIT License](LICENSE).
44
130
 
45
131
  ## Code of Conduct
46
132
 
47
- This project uses the [Contributor Code of Conduct](CODE_OF_CONDUCT.md). We ask everyone to please adhere by its guidelines.
133
+ This project uses the [Contributor Code of Conduct](CODE_OF_CONDUCT.md). We ask everyone to please adhere by its guidelines.
@@ -6,6 +6,9 @@ require_relative "orbit_activities/version"
6
6
  module OrbitActivities
7
7
  loader = Zeitwerk::Loader.new
8
8
  loader.tag = File.basename(__FILE__, ".rb")
9
+ loader.inflector.inflect({
10
+ 'Http' => 'HTTP'
11
+ })
9
12
  loader.push_dir(__dir__)
10
13
  loader.setup
11
14
  end
@@ -21,6 +21,12 @@ module OrbitActivities
21
21
 
22
22
  response = http.request(req)
23
23
 
24
+ if response.class == Net::HTTPTooManyRequests
25
+ puts "Reached rate limitation in API, retrying in 60 seconds..."
26
+ sleep(60)
27
+ response = http.request(req)
28
+ end
29
+
24
30
  validate_payload(response.body)
25
31
  end
26
32
 
@@ -5,6 +5,7 @@ require_relative "http"
5
5
  module OrbitActivities
6
6
  class Request
7
7
  attr_reader :api_key, :workspace_id, :user_agent, :action, :body, :filters, :member_id, :activity_id
8
+ attr_accessor :response
8
9
 
9
10
  def initialize(params = {})
10
11
  @action = params.fetch(:action)
@@ -15,6 +16,7 @@ module OrbitActivities
15
16
  @filters = params.fetch(:filters, nil)
16
17
  @member_id = params.fetch(:member_id, nil)
17
18
  @activity_id = params.fetch(:activity_id, nil)
19
+ @response = nil
18
20
 
19
21
  after_initialize!
20
22
  end
@@ -35,6 +37,8 @@ module OrbitActivities
35
37
  delete_post
36
38
  when "update_activity"
37
39
  update_activity
40
+ when "latest_activity_timestamp"
41
+ latest_activity_timestamp
38
42
  else
39
43
  raise ArgumentError,
40
44
  "Activity type is unrecognized. Must be one of: new_activity, list_activities, get_activity, list_member_activities, create_post, delete_post, update_activity"
@@ -42,7 +46,7 @@ module OrbitActivities
42
46
  end
43
47
 
44
48
  def new_activity
45
- OrbitActivities::HTTP.post(
49
+ @response = OrbitActivities::HTTP.post(
46
50
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities",
47
51
  user_agent: @user_agent,
48
52
  api_key: @api_key,
@@ -51,7 +55,7 @@ module OrbitActivities
51
55
  end
52
56
 
53
57
  def list_activities
54
- OrbitActivities::HTTP.get(
58
+ @response = OrbitActivities::HTTP.get(
55
59
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities",
56
60
  user_agent: @user_agent,
57
61
  api_key: @api_key,
@@ -59,8 +63,27 @@ module OrbitActivities
59
63
  )
60
64
  end
61
65
 
66
+ def latest_activity_timestamp
67
+ filters = {
68
+ items: 10,
69
+ direction: "DESC"
70
+ }
71
+ filters.merge!(@filters)
72
+
73
+ response = OrbitActivities::HTTP.get(
74
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities",
75
+ user_agent: @user_agent,
76
+ api_key: @api_key,
77
+ filters: filters
78
+ )
79
+
80
+ return nil if response["data"].nil? || response["data"].empty?
81
+
82
+ @response = response["data"][0]["attributes"]["created_at"]
83
+ end
84
+
62
85
  def get_activity
63
- OrbitActivities::HTTP.get(
86
+ @response = OrbitActivities::HTTP.get(
64
87
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities/#{@activity_id}",
65
88
  user_agent: @user_agent,
66
89
  api_key: @api_key
@@ -68,7 +91,7 @@ module OrbitActivities
68
91
  end
69
92
 
70
93
  def list_member_activities
71
- OrbitActivities::HTTP.get(
94
+ @response = OrbitActivities::HTTP.get(
72
95
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities",
73
96
  user_agent: @user_agent,
74
97
  api_key: @api_key,
@@ -77,7 +100,7 @@ module OrbitActivities
77
100
  end
78
101
 
79
102
  def create_post
80
- OrbitActivities::HTTP.post(
103
+ @response = OrbitActivities::HTTP.post(
81
104
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities",
82
105
  user_agent: @user_agent,
83
106
  api_key: @api_key,
@@ -86,7 +109,7 @@ module OrbitActivities
86
109
  end
87
110
 
88
111
  def delete_post
89
- OrbitActivities::HTTP.delete(
112
+ @response = OrbitActivities::HTTP.delete(
90
113
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities/#{@activity_id}",
91
114
  user_agent: @user_agent,
92
115
  api_key: @api_key
@@ -94,7 +117,7 @@ module OrbitActivities
94
117
  end
95
118
 
96
119
  def update_activity
97
- OrbitActivities::HTTP.put(
120
+ @response = OrbitActivities::HTTP.put(
98
121
  url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities/#{@activity_id}",
99
122
  user_agent: @user_agent,
100
123
  api_key: @api_key,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrbitActivities
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orbit_activities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orbit DevRel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-24 00:00:00.000000000 Z
12
+ date: 2021-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http