upkey-chatterly-client 1.0.1 → 1.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
  SHA1:
3
- metadata.gz: 0c34fff7e7ac926b7ff77ee39b00948daf64381a
4
- data.tar.gz: e0b1ee5ccbd98aa38239b7fa99fa7e4379bd36f3
3
+ metadata.gz: 38c3832e8406a454578d0e44b13e63142440ce47
4
+ data.tar.gz: 5aae37f1c8e9dc70521f79216aa17c6a7d840138
5
5
  SHA512:
6
- metadata.gz: e40667989cd123cd0a89602130ee59340db0241bb53f59bd3112f1ce3e8dc8360a6d2e65273f9d83a4b18778fe21735c162df0e0ed7d5c8256a831f60127a3fb
7
- data.tar.gz: 82278f3649ca189b2d413406a3cb2d5a642bc35370c981297f10c7b6dc508e5be55bc2075df8fe4d27b5cb725b25b0078cc3128bd05667333d42926aeeeee6c7
6
+ metadata.gz: 1c6b6334d11ad6bb1edcf89b1515602d7cde0f2caa31de08781737c050dc87417cf9e7ae005640d1ee12e53df1453beba9af30ed419de0079f2da087346462d4
7
+ data.tar.gz: 2f4b8361d0db4e11132454b6641eb3e2fc0e0d637da4a37aab6635b265313ab30bae82cbc089c3122ad3943bf6a4e278d4f07ceff0b4c8c2b3f098da00fb266c
data/README.md CHANGED
@@ -33,10 +33,10 @@ This will create a useable client, saved in `$chatterly`. There are now two inst
33
33
 
34
34
  ```ruby
35
35
  #Getting the Initial Message
36
- $chatterly.respond(:topic, topic_id)
36
+ $chatterly.respond({ key: :topic, id: topic_id })
37
37
 
38
38
  #Respoding to a User
39
- $chatterly.respond(:response, response_id)
39
+ $chatterly.respond({ key: :response, id: response_id })
40
40
  ```
41
41
 
42
42
  Both will respond with an `Upkey::Chatterly::Response` object, with two attributes: `message`, which will return the next message in the conversation (either the initial one for a topic or what the response linked to), and `responses`, which contains an array of options to respond to the given message.
@@ -1,8 +1,13 @@
1
1
  require 'upkey/chatterly/accessor'
2
2
  require 'upkey/chatterly/response'
3
3
 
4
+ require 'upkey/chatterly/urls/accessor'
5
+ require 'upkey/chatterly/urls/builder'
6
+ require 'upkey/chatterly/urls/response'
7
+
4
8
  require 'upkey/chatterly/alerts/missing_argument'
5
9
  require 'upkey/chatterly/errors/chatterly_argument_error'
10
+ require 'upkey/chatterly/errors/chatterly_error'
6
11
 
7
12
  require 'faraday'
8
13
  require 'json'
@@ -30,6 +35,17 @@ module Upkey
30
35
  Upkey::Chatterly::Response.new(message, resp)
31
36
  end
32
37
 
38
+ def method_missing(*args)
39
+ case args[0]
40
+ when :post_url
41
+ Upkey::Chatterly::Urls::Builder.post_url(args[1], self)
42
+ when :get_url
43
+ Upkey::Chatterly::Urls::Accessor.get_url(args[1], self)
44
+ else
45
+ raise NoMethodError
46
+ end
47
+ end
48
+
33
49
  private
34
50
 
35
51
  def set_up_faraday
@@ -0,0 +1,9 @@
1
+ module Upkey
2
+ module Chatterly
3
+ class ChatterlyError < StandardError
4
+ def initialize(msg="An unexpected error has occurred on Chatterly. If you are the owner of this app please check the logs for additional details.")
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,30 @@
1
+ module Upkey
2
+ module Chatterly
3
+ module Urls
4
+ module Accessor
5
+ def self.get_url(url, client)
6
+ @url = url
7
+ @client = client
8
+
9
+ access_chatterly
10
+ end
11
+
12
+ private
13
+
14
+ class << self
15
+ def access_chatterly
16
+ resp = @client.conn.get '/api/shortened_urls/0', url_params
17
+ Upkey::Chatterly::Urls::Response.new(resp)
18
+ end
19
+
20
+ def url_params
21
+ {
22
+ url: @url,
23
+ access_key: @client.access_key
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ module Upkey
2
+ module Chatterly
3
+ module Urls
4
+ module Builder
5
+ def self.post_url(url, client)
6
+ @url = url
7
+ @client = client
8
+
9
+ access_chatterly
10
+ end
11
+
12
+ private
13
+
14
+ class << self
15
+ def access_chatterly
16
+ resp = @client.conn.post '/api/shortened_urls', url_params
17
+ Upkey::Chatterly::Urls::Response.new(resp)
18
+ end
19
+
20
+ def url_params
21
+ {
22
+ shortened_url: {
23
+ url: @url
24
+ },
25
+ access_key: @client.access_key
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ module Upkey
2
+ module Chatterly
3
+ module Urls
4
+ class Response
5
+ attr_reader :contents, :status
6
+
7
+ def initialize(chatterly_response)
8
+ @status = chatterly_response.status
9
+
10
+ case status
11
+ when 200
12
+ @contents = JSON.parse(chatterly_response.body)
13
+ when 404
14
+ @contents = { message: 'Requested URL not found.' }
15
+ when 422
16
+ @contents = { message: JSON.parse(chatterly_response.body) }
17
+ when 401
18
+ @contents = { message: 'You are unauthorized to access this. Please check your access credentials and try again.' }
19
+ else
20
+ raise ChatterlyError
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Upkey
2
2
  module Chatterly
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upkey-chatterly-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ElliottAYoung
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,7 +102,11 @@ files:
102
102
  - lib/upkey/chatterly/alerts/missing_argument.rb
103
103
  - lib/upkey/chatterly/client.rb
104
104
  - lib/upkey/chatterly/errors/chatterly_argument_error.rb
105
+ - lib/upkey/chatterly/errors/chatterly_error.rb
105
106
  - lib/upkey/chatterly/response.rb
107
+ - lib/upkey/chatterly/urls/accessor.rb
108
+ - lib/upkey/chatterly/urls/builder.rb
109
+ - lib/upkey/chatterly/urls/response.rb
106
110
  - lib/upkey/chatterly/version.rb
107
111
  - upkey-chatterly-client.gemspec
108
112
  homepage: https://github.com/beupkey/upkey-chatterly-client.git