orbit_activities 0.0.2 → 0.1.0

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: dc1080c10767a93d1c123355c585449928dd1ad520b895bc479efbae3ceb6e5b
4
- data.tar.gz: 564bb88bbeeda2ceb8149b3a24a101e9872437322c8ded44d15aa00ac48832c1
3
+ metadata.gz: dc19e521a7103168771b57342dabb7bceffb4a051a52458102cd2c159d8e1ba4
4
+ data.tar.gz: f1dccee34992a1c77528bd1d83a07aee16c728f9341a57f134d7d981e8ab52bc
5
5
  SHA512:
6
- metadata.gz: 9608a1ee59c7bc5a2b09117b4979888b09966ef9e227b1d1d97ca46b9453930eed3e46dc3a3e560a36a03bd59225b52e971071f344e5665b7eb1b8a26dc15f11
7
- data.tar.gz: c237011ad251ac5493a78f79ee07f1a17f1bf8f67efb6862264be9cc6de71e9b85b58702da36bcffa254896a94a32b06e299eacbca5d2942a30bfeafb970e32d
6
+ metadata.gz: 80a6d164b1352cc746168545e1d3a6c4f55097da810ec867e6540c455edfdacfa4dce9dc2843c52ae7b37a32b79a72f3c9f143d1031835f1cfe11ca35d468540
7
+ data.tar.gz: 3e0f3ccba92e0fc6d404bb46f1a72f1c3177b5f9609adf465b5388adcf5ea0877c883a430efbd392eb93fab442d91205b10fb50b38e91df5cd30c06716ed2ad1
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ Exclude:
4
+ - 'spec/**/*'
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ Metrics/MethodLength:
18
+ Enabled: false
19
+
20
+ Style/GuardClause:
21
+ Enabled: false
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Enabled: false
28
+
29
+ Naming/AccessorMethodName:
30
+ Enabled: false
@@ -8,4 +8,4 @@ module OrbitActivities
8
8
  loader.tag = File.basename(__FILE__, ".rb")
9
9
  loader.push_dir(__dir__)
10
10
  loader.setup
11
- end
11
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require_relative "utils"
6
+
7
+ module OrbitActivities
8
+ class HTTP
9
+ def self.post(url:, user_agent:, api_key:, body:)
10
+ url = URI(url)
11
+
12
+ http = Net::HTTP.new(url.host, url.port)
13
+ http.use_ssl = true
14
+ req = Net::HTTP::Post.new(url)
15
+ req["Accept"] = "application/json"
16
+ req["Content-Type"] = "application/json"
17
+ req["Authorization"] = "Bearer #{api_key}"
18
+ req["User-Agent"] = user_agent
19
+
20
+ req.body = body
21
+
22
+ response = http.request(req)
23
+
24
+ validate_payload(response.body)
25
+ end
26
+
27
+ def self.get(url:, user_agent:, api_key:, filters: nil)
28
+ url = URI(url)
29
+ url.query = URI.encode_www_form(filters) if filters
30
+
31
+ http = Net::HTTP.new(url.host, url.port)
32
+ http.use_ssl = true
33
+ req = Net::HTTP::Get.new(url)
34
+ req["Accept"] = "application/json"
35
+ req["Authorization"] = "Bearer #{api_key}"
36
+ req["User-Agent"] = user_agent
37
+
38
+ response = http.request(req)
39
+
40
+ validate_payload(response.body)
41
+ end
42
+
43
+ def self.delete(url:, user_agent:, api_key:)
44
+ url = URI(url)
45
+
46
+ http = Net::HTTP.new(url.host, url.port)
47
+ http.use_ssl = true
48
+
49
+ req = Net::HTTP::Delete.new(url)
50
+ req["Authorization"] = "Bearer #{api_key}"
51
+ req["User-Agent"] = user_agent
52
+
53
+ response = http.request(req)
54
+
55
+ return "Deletion successful" if response.code == "204" || response.code == "200"
56
+
57
+ raise ArgumentError, response.message if response.code != "204" || response.code != "200"
58
+ end
59
+
60
+ def self.put(url:, user_agent:, api_key:, body:)
61
+ url = URI(url)
62
+
63
+ http = Net::HTTP.new(url.host, url.port)
64
+ http.use_ssl = true
65
+ req = Net::HTTP::Put.new(url)
66
+ req["Accept"] = "application/json"
67
+ req["Content-Type"] = "application/json"
68
+ req["Authorization"] = "Bearer #{api_key}"
69
+ req["User-Agent"] = user_agent
70
+
71
+ req.body = body
72
+
73
+ response = http.request(req)
74
+
75
+ return "Update successful" if response.code == "204" || response.code == "200"
76
+
77
+ raise ArgumentError, response.message if response.code != "204" || response.code != "200"
78
+ end
79
+
80
+ def self.validate_payload(payload)
81
+ JSON.parse(payload) if OrbitActivities::Utils.valid_json?(payload)
82
+ end
83
+ end
84
+ end
@@ -1,51 +1,105 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "json"
5
- require_relative "utils"
3
+ require_relative "http"
6
4
 
7
5
  module OrbitActivities
8
- class Request
9
- attr_reader :api_key, :workspace_id, :user_agent, :body
6
+ class Request
7
+ attr_reader :api_key, :workspace_id, :user_agent, :action, :body, :filters, :member_id, :activity_id
10
8
 
11
- def initialize(params = {})
12
- @api_key = params.fetch(:api_key)
13
- @workspace_id = params.fetch(:workspace_id)
14
- @user_agent = params.fetch(:user_agent, "ruby-orbit-activities/#{OrbitActivities::VERSION}")
15
- @body = params.fetch(:body)
9
+ def initialize(params = {})
10
+ @action = params.fetch(:action)
11
+ @api_key = params.fetch(:api_key)
12
+ @workspace_id = params.fetch(:workspace_id)
13
+ @user_agent = params.fetch(:user_agent, "ruby-orbit-activities/#{OrbitActivities::VERSION}")
14
+ @body = params.fetch(:body, nil)
15
+ @filters = params.fetch(:filters, nil)
16
+ @member_id = params.fetch(:member_id, nil)
17
+ @activity_id = params.fetch(:activity_id, nil)
16
18
 
17
- after_initialize!
18
- end
19
+ after_initialize!
20
+ end
19
21
 
20
- def after_initialize!
21
- call
22
- end
22
+ def after_initialize!
23
+ case @action
24
+ when "new_activity"
25
+ new_activity
26
+ when "list_activities"
27
+ list_activities
28
+ when "get_activity"
29
+ get_activity
30
+ when "list_member_activities"
31
+ list_member_activities
32
+ when "create_post"
33
+ create_post
34
+ when "delete_post"
35
+ delete_post
36
+ when "update_activity"
37
+ update_activity
38
+ else
39
+ raise ArgumentError,
40
+ "Activity type is unrecognized. Must be one of: new_activity, list_activities, get_activity, list_member_activities, create_post, delete_post, update_activity"
41
+ end
42
+ end
23
43
 
24
- def call
25
- payload = make_request
26
- validate_payload(payload)
27
- end
44
+ def new_activity
45
+ OrbitActivities::HTTP.post(
46
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities",
47
+ user_agent: @user_agent,
48
+ api_key: @api_key,
49
+ body: @body
50
+ )
51
+ end
28
52
 
29
- def make_request
30
- url = URI("https://app.orbit.love/api/v1/#{@workspace_id}/activities")
53
+ def list_activities
54
+ OrbitActivities::HTTP.get(
55
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities",
56
+ user_agent: @user_agent,
57
+ api_key: @api_key,
58
+ filters: @filters
59
+ )
60
+ end
31
61
 
32
- http = Net::HTTP.new(url.host, url.port)
33
- http.use_ssl = true
34
- req = Net::HTTP::Post.new(url)
35
- req["Accept"] = "application/json"
36
- req["Content-Type"] = "application/json"
37
- req["Authorization"] = "Bearer #{@api_key}"
38
- req["User-Agent"] = @user_agent
62
+ def get_activity
63
+ OrbitActivities::HTTP.get(
64
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/activities/#{@activity_id}",
65
+ user_agent: @user_agent,
66
+ api_key: @api_key
67
+ )
68
+ end
39
69
 
40
- req.body = @body
70
+ def list_member_activities
71
+ OrbitActivities::HTTP.get(
72
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities",
73
+ user_agent: @user_agent,
74
+ api_key: @api_key,
75
+ filters: @filters
76
+ )
77
+ end
41
78
 
42
- response = http.request(req)
79
+ def create_post
80
+ OrbitActivities::HTTP.post(
81
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities",
82
+ user_agent: @user_agent,
83
+ api_key: @api_key,
84
+ body: @body
85
+ )
86
+ end
43
87
 
44
- response.body
45
- end
88
+ def delete_post
89
+ OrbitActivities::HTTP.delete(
90
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities/#{@activity_id}",
91
+ user_agent: @user_agent,
92
+ api_key: @api_key
93
+ )
94
+ end
46
95
 
47
- def validate_payload(payload)
48
- JSON.parse(payload) if OrbitActivities::Utils.valid_json?(payload)
49
- end
96
+ def update_activity
97
+ OrbitActivities::HTTP.put(
98
+ url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/activities/#{@activity_id}",
99
+ user_agent: @user_agent,
100
+ api_key: @api_key,
101
+ body: @body
102
+ )
50
103
  end
51
- end
104
+ end
105
+ end
@@ -5,7 +5,8 @@ module OrbitActivities
5
5
  def self.valid_json?(string)
6
6
  !JSON.parse(string).nil?
7
7
  rescue JSON::ParserError
8
- raise ArgumentError, "Expected confirmation from the Orbit API, but received nothing. Please check your logs and try again."
8
+ raise ArgumentError,
9
+ "Expected confirmation from the Orbit API, but received nothing. Please check your logs and try again."
9
10
  end
10
11
  end
11
- end
12
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OrbitActivities
4
- VERSION = "0.0.2"
5
- end
6
-
4
+ VERSION = "0.1.0"
5
+ end
@@ -28,10 +28,10 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_dependency "http", "~> 4.4"
30
30
  spec.add_dependency "json", "~> 2.5"
31
- spec.add_dependency "zeitwerk", "~> 2.4"
32
31
  spec.add_dependency "rake", "~> 13.0"
32
+ spec.add_dependency "zeitwerk", "~> 2.4"
33
+ spec.add_development_dependency "byebug"
33
34
  spec.add_development_dependency "rspec", "~> 3.4"
34
- spec.add_development_dependency "webmock", "~> 3.12"
35
35
  spec.add_development_dependency "rubocop", "~> 1.7"
36
- spec.add_development_dependency "byebug"
37
- end
36
+ spec.add_development_dependency "webmock", "~> 3.12"
37
+ 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.0.2
4
+ version: 0.1.0
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-18 00:00:00.000000000 Z
12
+ date: 2021-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -40,61 +40,61 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.5'
42
42
  - !ruby/object:Gem::Dependency
43
- name: zeitwerk
43
+ name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '2.4'
48
+ version: '13.0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '2.4'
55
+ version: '13.0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: rake
57
+ name: zeitwerk
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '13.0'
62
+ version: '2.4'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '13.0'
69
+ version: '2.4'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rspec
71
+ name: byebug
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '3.4'
76
+ version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '3.4'
83
+ version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: webmock
85
+ name: rspec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '3.12'
90
+ version: '3.4'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '3.12'
97
+ version: '3.4'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rubocop
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -110,19 +110,19 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.7'
112
112
  - !ruby/object:Gem::Dependency
113
- name: byebug
113
+ name: webmock
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: '3.12'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: '3.12'
126
126
  description: This gem helps you build custom activities for Orbit workspaces using
127
127
  the Orbit API
128
128
  email:
@@ -135,6 +135,7 @@ extra_rdoc_files: []
135
135
  files:
136
136
  - ".github/workflows/ci.yml"
137
137
  - ".gitignore"
138
+ - ".rubocop.yml"
138
139
  - CODE_OF_CONDUCT.md
139
140
  - CONTRIBUTING.md
140
141
  - Gemfile
@@ -144,6 +145,7 @@ files:
144
145
  - bin/console
145
146
  - bin/setup
146
147
  - lib/orbit_activities.rb
148
+ - lib/orbit_activities/http.rb
147
149
  - lib/orbit_activities/request.rb
148
150
  - lib/orbit_activities/utils.rb
149
151
  - lib/orbit_activities/version.rb