intercom 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,5 +4,6 @@
4
4
  Gemfile.lock
5
5
  pkg/*
6
6
  .rakeTasks
7
+ .yardoc
7
8
  spike.rb
8
9
  html
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011- Intercom App, Inc. (https://www.intercom.io)
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,35 +1,57 @@
1
1
  Ruby bindings for the Intercom API (https://api.intercom.io). See http://docs.intercom.io/api for more details
2
2
 
3
+ ## Install
4
+ ```
5
+ gem install intercom
6
+ ```
7
+
3
8
  ## Basic Usage
4
9
 
5
10
  ### Configure your access credentials
6
11
 
7
12
  ```
8
- Intercom.app_id = "my_app_id"
9
- Intercom.secret_key = "my-super-crazy-secret"
13
+ Intercom.app_id = "my_app_iddd"
14
+ Intercom.api_key = "my-super-crazy-api-key"
10
15
  ```
11
16
 
12
17
  ### Resources
13
18
 
14
- All methods in this API operate in the context of a single user. Users are identified by either an '''email''' address or a '''user_id'''.
15
- One of these is required as input to every operation.
19
+ The API supports:
20
+
21
+ ```
22
+ POST,PUT,GET https://api.intercom.io/v1/users
23
+ POST,PUT,GET https://api.intercom.io/v1/users/messages
24
+ POST https://api.intercom.io/v1/users/impressions
25
+ ```
16
26
 
17
27
  #### Users
18
28
 
29
+ ```ruby
19
30
  user = Intercom::User.find(:email => "bob@example.com")
20
31
  user = Intercom::User.create(params)
21
32
  user = Intercom::User.new(params)
22
33
  user.save
34
+ ```
23
35
 
24
36
  #### Messages
25
37
 
38
+ ```ruby
26
39
  Intercom::Message.create
27
40
  Intercom::Message.find
28
41
  Intercom::Message.find_all
29
42
  Intercom::Message.mark_as_read
43
+ ```
30
44
 
31
45
  #### Impressions
32
46
 
47
+ ```ruby
33
48
  Intercom::Impression.create
49
+ ```
34
50
 
35
51
  ### Errors
52
+
53
+ ```ruby
54
+ Intercom::AuthenticationError
55
+ Intercom::ServerError
56
+ Intercom::ResourceNotFound
57
+ ```
data/changed.txt ADDED
@@ -0,0 +1,8 @@
1
+ 0.0.3
2
+ - renamed Intercom.secret_key to Intercom.api_key for consistency throughout our app and docs
3
+
4
+ 0.0.2
5
+ - updates to reflect changes to resources served by the api
6
+
7
+ 0.0.1
8
+ - experimental version
data/intercom.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ["ben@intercom.io", "ciaran@intercom.io", "darragh@intercom.io"]
10
10
  s.homepage = "http://www.intercom.io"
11
11
  s.summary = %q{Ruby bindings for the Intercom API}
12
- s.description = %q{Intercom is a customer relationship management and messaging tool for web app owners. See https://www.intercom.io for more details.}
12
+ s.description = %Q{Intercom (https://www.intercom.io) is a customer relationship management and messaging tool for web app owners. This library wraps the api provided by Intercom. See http://docs.intercom.io/api for more details. }
13
13
 
14
14
  s.rubyforge_project = "intercom"
15
15
 
data/lib/intercom.rb CHANGED
@@ -14,7 +14,7 @@ require "json"
14
14
  # == Basic Usage
15
15
  # === Configure Intercom with your access credentials
16
16
  # Intercom.app_id = "my_app_id"
17
- # Intercom.secret_key = "my_secret_key"
17
+ # Intercom.api_key = "my_api_key"
18
18
  # === Make requests to the API
19
19
  # Intercom::User.find(:email => "bob@example.com")
20
20
  #
@@ -22,7 +22,7 @@ module Intercom
22
22
  @hostname = "api.intercom.io"
23
23
  @protocol = "https"
24
24
  @app_id = nil
25
- @secret_key = nil
25
+ @api_key = nil
26
26
 
27
27
  ##
28
28
  # Set the id of the application you want to interact with.
@@ -32,17 +32,17 @@ module Intercom
32
32
  end
33
33
 
34
34
  ##
35
- # Set the secret key to gain access to your application data.
35
+ # Set the api key to gain access to your application data.
36
36
  # When logged into your intercom console, you can view/create api keys in the settings menu
37
- def self.secret_key=(secret_key)
38
- @secret_key = secret_key
37
+ def self.api_key=(api_key)
38
+ @api_key = api_key
39
39
  end
40
40
 
41
41
 
42
42
  private
43
43
  def self.url_for_path(path)
44
- raise ArgumentError, "You must set both Intercom.app_id and Intercom.secret_key to use this client. See https://github.com/intercom/intercom for usage examples." if [@app_id, @secret_key].any?(&:nil?)
45
- "#{protocol}://#{@app_id}:#{@secret_key}@#{hostname}/v1/#{path}"
44
+ raise ArgumentError, "You must set both Intercom.app_id and Intercom.api_key to use this client. See https://github.com/intercom/intercom for usage examples." if [@app_id, @api_key].any?(&:nil?)
45
+ "#{protocol}://#{@app_id}:#{@api_key}@#{hostname}/v1/#{path}"
46
46
  end
47
47
 
48
48
  def self.post(path, payload_hash)
@@ -107,6 +107,9 @@ module Intercom
107
107
  @hostname = override
108
108
  end
109
109
 
110
+ #
111
+ # Raised when the credentials you provide don't match a valid account on Intercom.
112
+ # Check that you have set <b>Intercom.app_id=</b> and <b>Intercom.api_key=</b> correctly.
110
113
  class AuthenticationError < StandardError;
111
114
  end
112
115
 
@@ -4,42 +4,56 @@ module Intercom
4
4
 
5
5
  ##
6
6
  # Represents a users interaction with your app (eg page view, or using a particular feature)
7
+ #
8
+ # An impressions contains user_ip, user_agent and location.
9
+ #
10
+ # impression = Intercom::Impression.create(:email => "person@example.com", :location => "/pricing/upgrade",
11
+ # :user_ip => '1.2.3.4', :user_agent => "my-service-iphone-app-1.2")
12
+ # The impression response will contain {#unread_messages}
13
+ # impression.unread_messages
14
+ # You can also create an impression and save it like this:
15
+ # impression = Intercom::Impression.new
16
+ # impression.email = "person@example.com"
17
+ # impression.location = "person@example.com"
18
+ # ....
19
+ # impression.save
7
20
  class Impression < UserResource
8
21
  ##
9
- # Records that a user has interacted with your application, including the 'location' within the app they used
22
+ # Creates a new Impression using params and saves it
23
+ # @see #save
10
24
  def self.create(params)
11
25
  Impression.new(params).save
12
26
  end
13
27
 
28
+ ##
29
+ # Records that a user has interacted with your application, including the 'location' within the app they used
14
30
  def save
15
31
  response = Intercom.post("users/impressions", to_hash)
16
32
  self.update_from_api_response(response)
17
33
  end
18
34
 
35
+ ##
36
+ # Set the ip address of the user for this impression
19
37
  def user_ip=(user_ip)
20
38
  @attributes["user_ip"] = user_ip
21
39
  end
22
40
 
23
- def user_ip
24
- @attributes["user_ip"]
25
- end
26
-
41
+ ##
42
+ # Set the location in your application that this impression occurred. E.g. the url in a web app, or perhaps the screen in a desktop or phone application.
27
43
  def location=(location)
28
44
  @attributes["location"] = location
29
45
  end
30
46
 
31
- def location
32
- @attributes["location"]
33
- end
34
-
47
+ ##
48
+ # Set the user agent of the user this impression (E.g. their browser user agent, or the name and version of a desktop or phone application)
35
49
  def user_agent=(user_agent)
36
50
  @attributes["user_agent"] = user_agent
37
51
  end
38
52
 
39
- def user_agent
40
- @attributes["user_agent"]
41
- end
42
-
53
+ ##
54
+ # For convenience, after saving, the unread_messages count will be updated with the number of unread messages for the user for their current location.
55
+ #
56
+ # Remember, Auto Messages (http://docs.intercom.io/#AutoMessages) can be targeted to only show when a user views a particular page in your application.
43
57
  def unread_messages
44
58
  @attributes["unread_messages"]
45
59
  end
@@ -58,7 +58,6 @@ module Intercom
58
58
  time_at("updated_at")
59
59
  end
60
60
 
61
-
62
61
  def thread_id=(thread_id)
63
62
  @attributes["thread_id"] = thread_id
64
63
  end
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -4,7 +4,7 @@ require 'minitest/autorun'
4
4
  describe "api.intercom.io dummy data requests" do
5
5
  before :each do
6
6
  Intercom.app_id = "dummy-app-id"
7
- Intercom.secret_key = "dummy-secret-key"
7
+ Intercom.api_key = "dummy-secret-key"
8
8
  end
9
9
 
10
10
  it "should get a user" do
@@ -22,7 +22,11 @@ describe "api.intercom.io dummy data requests" do
22
22
 
23
23
  it "authentication failure with bad api key" do
24
24
  Intercom.app_id = "bad-app-id"
25
- Intercom.secret_key = "bad-secret-key"
25
+ Intercom.api_key = "bad-secret-key"
26
26
  proc { Intercom::User.find(:email => "not-found@example.com") }.must_raise Intercom::AuthenticationError
27
27
  end
28
+
29
+ it "should find_all messages for a user" do
30
+ Intercom::MessageThread.find_all(:email => "somebody@example.com")
31
+ end
28
32
  end
@@ -8,13 +8,13 @@ describe Intercom do
8
8
  describe "API" do
9
9
  before do
10
10
  Intercom.app_id = "abc123"
11
- Intercom.secret_key = "super-secret-key"
11
+ Intercom.api_key = "super-secret-key"
12
12
  end
13
13
 
14
- it "raises ArgumentError if no app_id or secret_key specified" do
14
+ it "raises ArgumentError if no app_id or api_key specified" do
15
15
  Intercom.app_id = nil
16
- Intercom.secret_key = nil
17
- proc { Intercom.url_for_path("something") }.must_raise ArgumentError, "You must set both Intercom.app_id and Intercom.secret_key to use this client. See https://github.com/intercom/intercom-ruby for usage examples."
16
+ Intercom.api_key = nil
17
+ proc { Intercom.url_for_path("something") }.must_raise ArgumentError, "You must set both Intercom.app_id and Intercom.api_key to use this client. See https://github.com/intercom/intercom-ruby for usage examples."
18
18
  end
19
19
 
20
20
  it "defaults to https to api.intercom.io" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-03-05 00:00:00.000000000Z
14
+ date: 2012-03-06 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client
18
- requirement: &70093820212260 !ruby/object:Gem::Requirement
18
+ requirement: &70197574767120 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70093820212260
26
+ version_requirements: *70197574767120
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
- requirement: &70093820211560 !ruby/object:Gem::Requirement
29
+ requirement: &70197574748440 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *70093820211560
37
+ version_requirements: *70197574748440
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rdoc
40
- requirement: &70093820202300 !ruby/object:Gem::Requirement
40
+ requirement: &70197574686840 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70093820202300
48
+ version_requirements: *70197574686840
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &70093820198940 !ruby/object:Gem::Requirement
51
+ requirement: &70197570625140 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70093820198940
59
+ version_requirements: *70197570625140
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: mocha
62
- requirement: &70093820196440 !ruby/object:Gem::Requirement
62
+ requirement: &70197570614200 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,9 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70093820196440
71
- description: Intercom is a customer relationship management and messaging tool for
72
- web app owners. See https://www.intercom.io for more details.
70
+ version_requirements: *70197570614200
71
+ description: ! 'Intercom (https://www.intercom.io) is a customer relationship management
72
+ and messaging tool for web app owners. This library wraps the api provided by Intercom.
73
+ See http://docs.intercom.io/api for more details. '
73
74
  email:
74
75
  - ben@intercom.io
75
76
  - ciaran@intercom.io
@@ -80,9 +81,11 @@ extra_rdoc_files: []
80
81
  files:
81
82
  - .gitignore
82
83
  - Gemfile
84
+ - LICENSE
83
85
  - README.md
84
86
  - README.rdoc
85
87
  - Rakefile
88
+ - changed.txt
86
89
  - intercom.gemspec
87
90
  - lib/data/cacert.pem
88
91
  - lib/intercom.rb