guidepost 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5f5e8180cd498e7176833394eebb66091c6f24c9f6b8c59c2cdc1aa6aed34464
4
+ data.tar.gz: dea372997e357359bf582c5818e0bbd11c7b32cfbd99daa46d1d3cd22c32b738
5
+ SHA512:
6
+ metadata.gz: c318c6a46816f326acab6b07352a11b48797cdba5b6f0fbef9020b64bb73495fee2006d5cd84b40d5f6b51c8309e55aae9075e7718d67b820e3cccc526560b16
7
+ data.tar.gz: 9e325c772b8a5c6ed65615967392fa9734b5497d5f8b20a2821065d708456b1d38bb6d86e6610ff27c3446bb510ba93a459d9d42463168ac29a25fc0542c6a29
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Kiren Srinivasan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,101 @@
1
+ # Guidepost
2
+
3
+ ## Purpose
4
+
5
+ Your knowledge base is a hugely important component of your company! The purpose of this project is to help you gain more control over it.
6
+
7
+ ## Table of Contents
8
+
9
+ * [Prerequisites/Requirements](#prerequisites-requirements)
10
+ * [Current Knowledge Base Providers](#current-knowledge-base-providers)
11
+ * [Current Storage Services](#current-storage-services)
12
+ * [Installation](#installation)
13
+ * [Environment Variables](#environment-variables)
14
+ * [Current Use Cases](#current-use-cases)
15
+ * [Contact](#contact)
16
+ * [Roadmap](#roadmap)
17
+ * [License](#license)
18
+
19
+ ### Prerequisites/Requirements
20
+
21
+ * Rails 4.2+
22
+ * Ruby 2.5+
23
+
24
+ ### Current Knowledge Base Providers
25
+
26
+ * Zendesk
27
+
28
+ If you're looking to use this gem, but work with providers like Freshdesk, Zoho, and Confluence, feel free to reach out!
29
+
30
+ ### Current Storage Services
31
+
32
+ * Amazon Simple Storage Service (Amazon S3)
33
+
34
+ If you're looking to use this gem, but work with other storage services like Google Cloud Storage, feel free to reach out!
35
+
36
+ ### Installation
37
+
38
+ Add this line to your application's Gemfile:
39
+
40
+ ```ruby
41
+ gem 'guidepost'
42
+ ```
43
+
44
+ And then execute:
45
+
46
+ $ bundle
47
+
48
+ ### Environment Variables
49
+
50
+ Make sure to have certain environmental variables set, preferrably in your `.bash_profile` or in your `.bashrc`! The prefix of each environment variable needs to be the uppercased version of the name of your project that you will use to initialize your `Guidepost::Provider` (i.e. Zendesk in this case, since this is the only provider currently supported):
51
+
52
+ #### Zendesk
53
+
54
+ ```ruby
55
+ # The email associated with your Zendesk subdomain
56
+ ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_ZENDESK_EMAIL"]
57
+
58
+ # The password token associated with your Zendesk subdomain
59
+ ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_PASSWORD_TOKEN"]
60
+ ```
61
+
62
+ #### S3
63
+
64
+ ```ruby
65
+ # The access key associated with your AWS account
66
+ ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_AWS_ACCESS_KEY_ID"]
67
+
68
+ # The secret key associated with your AWS account
69
+ ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_AWS_SECRET_ACCESS_KEY"]
70
+
71
+ # The name of the S3 bucket you want to upload your backups to
72
+ ENV["#{YOUR_PROJECT_NAME}_GUIDEPOST_S3_BUCKET_NAME"]
73
+ ```
74
+
75
+ ### Current Use Cases
76
+
77
+ * Back up your knowledge base to S3
78
+
79
+ #### Back up your knowledge base to S3
80
+
81
+ ```ruby
82
+ subdomain = "example"
83
+ project_name = "example"
84
+
85
+ zendesk = Guidepost::Provider::Zendesk.new(subdomain: subdomain, project_name: project_name)
86
+ zendesk.backup_all_articles
87
+ ```
88
+
89
+ ## Contact
90
+
91
+ If you find and want to address any security issues with the project, email [Kiren Srinivasan](mailto:srinitude@gmail.com.com)! For anything else, feel free to file a Github issue or tweet me [@srinitude](https://twitter.com/srinitude).
92
+
93
+ ## Roadmap
94
+
95
+ * Tests
96
+ * More robust documentation
97
+ * More relevant use cases
98
+
99
+ ## License
100
+
101
+ Guidepost is released under the [MIT License](LICENSE).
@@ -0,0 +1,16 @@
1
+ require 'aws-sdk'
2
+ require 'cgi'
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ module Guidepost
7
+
8
+ module Provider
9
+ autoload :Zendesk, 'guidepost/provider/zendesk'
10
+ end
11
+
12
+ module Storage
13
+ autoload :S3, 'guidepost/storage/s3'
14
+ end
15
+
16
+ end
@@ -0,0 +1,67 @@
1
+ module Guidepost
2
+ module Provider
3
+ class Zendesk
4
+ attr_accessor :subdomain
5
+ attr_accessor :project_name
6
+
7
+ def initialize(options={})
8
+ @subdomain = options[:subdomain]
9
+ @project_name = options[:project_name]
10
+
11
+ raise "Guidepost::Provider::Zendesk initializer is missing either a subdomain or project_name" if @subdomain.nil? || @project_name.nil?
12
+
13
+ @project_name.upcase!
14
+ @storage = options[:storage] || Guidepost::Storage::S3.new(project_name: @project_name)
15
+
16
+ @email = "#{ENV["#{@project_name}_GUIDEPOST_ZENDESK_EMAIL"]}/token"
17
+ @password = ENV["#{@project_name}_GUIDEPOST_ZENDESK_PASSWORD_TOKEN"]
18
+ end
19
+
20
+ def backup_all_articles
21
+ # Get all articles (with pagination)
22
+ articles = self.retrieve_all_articles
23
+
24
+ # Upload to S3
25
+ timestamp = Time.now.strftime('%Y%m%d%H%M%S')
26
+ @storage.upload_file(path: "zendesk/article_backups/#{timestamp}.json", string_content: articles.to_json)
27
+
28
+ articles.count
29
+ end
30
+
31
+ def retrieve_all_articles
32
+ articles = []
33
+ page_next = nil
34
+ while true
35
+ page_articles, page_next = self.retrieve_articles(page_next)
36
+ break if page_articles.nil? || page_articles.empty?
37
+ articles += page_articles
38
+ break if page_next.nil?
39
+ end
40
+ articles
41
+ end
42
+
43
+ def retrieve_articles(url)
44
+ url = "#{self.base_api_url}/help_center/articles.json?include=translations&per_page=25&page=1" if url.nil?
45
+
46
+ uri = URI.parse(url)
47
+
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ http.use_ssl = true
50
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
51
+
52
+ request = Net::HTTP::Get.new(uri.request_uri)
53
+ request.basic_auth(@email, @password)
54
+ response = http.request(request)
55
+
56
+ body = response.body.force_encoding("UTF-8")
57
+
58
+ j_body = JSON.parse(body)
59
+ return j_body['articles'], j_body['next_page']
60
+ end
61
+
62
+ def base_api_url
63
+ "https://#{self.subdomain}.zendesk.com/api/v2"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,45 @@
1
+ module Guidepost
2
+ module Storage
3
+ class S3
4
+ attr_accessor :project_name
5
+
6
+ def initialize(options={})
7
+ @project_name = options[:project_name]
8
+
9
+ raise "Guidepost::Storage::S3 initializer is missing a project_name" if @project_name.nil?
10
+
11
+ @project_name.upcase!
12
+
13
+ @s3_client = Aws::S3::Resource.new(
14
+ credentials: Aws::Credentials.new(ENV["#{@project_name}_GUIDEPOST_AWS_ACCESS_KEY_ID"], ENV["#{@project_name}_GUIDEPOST_AWS_SECRET_ACCESS_KEY"]),
15
+ region: ENV["#{@project_name}_GUIDEPOST_AWS_REGION"] || "us-east-1"
16
+ )
17
+ end
18
+
19
+ def upload_file(options={})
20
+ path = options.fetch(:path, nil)
21
+ string_content = options.fetch(:string_content, "")
22
+ acl = options.fetch(:acl, "private")
23
+ metadata = options.fetch(:metadata, nil)
24
+
25
+ bucket_name = ENV["#{self.project_name}_GUIDEPOST_S3_BUCKET_NAME"]
26
+ storage_class = ENV["#{self.project_name}_GUIDEPOST_S3_STORAGE_CLASS"] || "STANDARD_IA"
27
+
28
+ return false if path.nil?
29
+ begin
30
+ obj = @s3_client.bucket(bucket_name).object(path)
31
+ result = obj.put({
32
+ body: string_content,
33
+ acl: acl,
34
+ storage_class: storage_class,
35
+ metadata: metadata,
36
+ })
37
+ rescue Seahorse::Client::NetworkingError => e
38
+ raise e if !Rails.env.test?
39
+ return true
40
+ end
41
+ return !result.nil?
42
+ end
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guidepost
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kiren Srinivasan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Harness your knowledge base in your Ruby applications
28
+ email: kiren.srinivasan@holbertonschool.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - lib/guidepost.rb
36
+ - lib/guidepost/provider/zendesk.rb
37
+ - lib/guidepost/storage/s3.rb
38
+ homepage:
39
+ licenses: []
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.5.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.7.6
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Harness your knowledge base in your Ruby applications
61
+ test_files: []