commsworld-crm-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/crm +69 -0
  3. metadata +86 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5ac6ba4638badfe5922257e18695f4854fd22c0b286cd1b262172f4652b407ab
4
+ data.tar.gz: 71301d32e76c78fc09dd962a9968a6730c6d07775f6dfa5957de75b3e3417a81
5
+ SHA512:
6
+ metadata.gz: 58d53f3262106deb5295a526e802afb3ace5c41a8625d97b711470a13bf8a279e881de4093a14d93071c0050e992f539742a7f18754a831baae0713c9337dc16
7
+ data.tar.gz: cf5a4609e8f6ff5dd9e07f2d3dce9edbb941e1976dff6d9d28f65ca19d30bda6eec09645a9b79cf8be4115d27d48321072bb068566a2aee3b93791a7c3437dd9
data/bin/crm ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+ require "thor"
6
+
7
+ def filter_keys(hash, keys)
8
+ hash.select { |key, value| keys.include?(key) }
9
+ end
10
+
11
+ AUTHENTICATION_FILE = File.join(Dir.home, ".crm-cli-api-key").freeze
12
+
13
+ module CRM
14
+ # CRM API Client factory
15
+ class Client
16
+ def self.connect(api_key: nil)
17
+ Faraday.new(url: "https://crm.commsworld.com", headers: { "X-API-Key" => api_key }) do |conn|
18
+ conn.response :json, :content_type => /\bjson$/
19
+ conn.adapter Faraday.default_adapter
20
+ end
21
+ end
22
+ end
23
+
24
+ # CRM Command Line Interface
25
+ class CLI < Thor
26
+ desc "auth", "Configure authentication for this tool before running commands which require authentication"
27
+ def auth
28
+ puts "Visit https://crm.commsworld.com/profile#authentication and enter your API key here:"
29
+ api_key = ask("API Key:", echo: false)
30
+
31
+ File.open(AUTHENTICATION_FILE, "w").write(api_key.strip)
32
+ end
33
+
34
+
35
+ desc "whoami", "Show who the currently authenticated user is"
36
+ def whoami
37
+ response = Client.connect(api_key: authentication).get("/api/me")
38
+ print_table filter_keys(response.body.fetch("user"), ["name", "email", "disabled", "staff", "admin", "superuser", "organisation"])
39
+ end
40
+
41
+ desc "whois", "Display information about a person when an id is supplied"
42
+ def whois(person_id)
43
+ # require_authentication!
44
+
45
+ response = Client.connect(api_key: authentication).get("/api/people/#{person_id}")
46
+ raise Thor::Error, "Person with id #{person_id} was not found." unless response.status == 200
47
+
48
+ print_table filter_keys(response.body.fetch("person"), ["name", "email", "disabled", "staff", "admin", "superuser", "organisation"])
49
+ end
50
+
51
+ private
52
+
53
+ def authentication
54
+ @authentication ||= File.open(AUTHENTICATION_FILE).read
55
+ rescue Errno::ENOENT
56
+ require_authentication!
57
+ end
58
+
59
+ def require_authentication!
60
+ if File.exist?(AUTHENTICATION_FILE)
61
+ @authentication = File.open(AUTHENTICATION_FILE).read
62
+ else
63
+ raise Thor::Error, "This command requires authentication. Please run `crm auth` first."
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ CRM::CLI.start(ARGV)
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commsworld-crm-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Commsworld
8
+ - Lewis Eason
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-12-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: thor
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: This tool is completely unsupported, and probably isn't useful to you.
57
+ email:
58
+ executables:
59
+ - crm
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - bin/crm
64
+ homepage:
65
+ licenses: []
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.0.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Command line utility for interacting with the Commsworld CRM.
86
+ test_files: []