intercom 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.iml
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in intercom.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ guard 'minitest', :all_on_start => false, :all_after_pass => false do
2
+ watch(%r|^spec/(.*)_spec\.rb|)
3
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
4
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
5
+ end
@@ -0,0 +1,16 @@
1
+ ## Usage
2
+
3
+ ```
4
+ Intercom.app_id = "my_app_id"
5
+ Intercom.secret_key = "my-super-crazy-secret"
6
+
7
+ user = Intercom::User.new(
8
+ :email => 'joe@example.com'
9
+ ...
10
+ )
11
+ user.save
12
+
13
+ ...
14
+
15
+ user = Intercom::User.find(:email => 'joe@example.com')
16
+ ```
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:spec) do |spec|
5
+ spec.libs.push "lib"
6
+ spec.libs.push "spec"
7
+ spec.test_files = FileList['spec/**/*_spec.rb']
8
+ spec.warning = true
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "intercom/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "intercom"
7
+ s.version = Intercom::VERSION
8
+ s.authors = ["Ben McRedmond", "Ciaran Lee", "Darragh Curran",]
9
+ s.email = ["ben@intercom.io", "ciaran@intercom.io", "darragh@intercom.io"]
10
+ s.homepage = "http://intercom.io"
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 http://intercom.io for more details.}
13
+
14
+ s.rubyforge_project = "intercom"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "rest-client"
22
+ s.add_development_dependency 'minitest'
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'guard'
25
+ s.add_development_dependency 'guard-minitest'
26
+ s.add_development_dependency 'pry'
27
+ s.add_development_dependency 'mocha'
28
+ end
@@ -0,0 +1,53 @@
1
+ require "intercom/version"
2
+ require "rest_client"
3
+ require 'json'
4
+
5
+ module Intercom
6
+ def self.app_id=(app_id)
7
+ @app_id = app_id
8
+ end
9
+
10
+ def self.secret_key=(secret_key)
11
+ @secret_key = secret_key
12
+ end
13
+
14
+ def self.protocol
15
+ "https"
16
+ end
17
+
18
+ def self.hostname
19
+ "api.intercom.io"
20
+ end
21
+
22
+ def self.execute_request(method, path, params = {}, headers = {}, payload = nil)
23
+ url = "https://#{@app_id}:#{@secret_key}@api.intercom.io/v1/#{path}"
24
+ args = {
25
+ :method => method,
26
+ :url => url,
27
+ :headers => {:params => params}.merge(headers),
28
+ :open_timeout => 10,
29
+ :payload => payload,
30
+ :timeout => 30
31
+ }
32
+ RestClient::Request.execute(args)
33
+ end
34
+
35
+ class User
36
+ def initialize(response)
37
+ @response = response
38
+ end
39
+
40
+ def self.find(params)
41
+ response = Intercom.execute_request(:get, "users", params)
42
+ User.new(response)
43
+ end
44
+
45
+ def save
46
+ Intercom.execute_request(:post, "users", {}, {:content_type => :json}, {"email" => "bo@example.com"}.to_json)
47
+ end
48
+
49
+ def method_missing(method, *args, &block)
50
+ @response[method.to_sym]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Intercom
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe Intercom do
4
+ before do
5
+ Intercom.app_id = "abc123"
6
+ Intercom.secret_key = "super-secret-key"
7
+ @mock_rest_client = Intercom.mock_rest_client = mock()
8
+ end
9
+
10
+ it "has a version number" do
11
+ Intercom::VERSION.must_equal "0.0.1"
12
+ end
13
+
14
+ describe "/v1/users" do
15
+ describe "get" do
16
+ it "fetches a user" do
17
+ @mock_rest_client.expects(:get).with("users", {"email" => "bo@example.com"}).returns(test_user)
18
+ user = Intercom::User.find("email" => "bo@example.com")
19
+ user.email.must_equal "bo@example.com"
20
+ user.name.must_equal "Joe Schmoe"
21
+ user.session_count.must_equal 123
22
+ end
23
+ end
24
+
25
+ describe "post" do
26
+ it "saves a user" do
27
+ user = Intercom::User.new("email" => "jo@example.com", "user_id" => "i-1224242")
28
+ @mock_rest_client.expects(:post).with("users", {}, {:content_type => :json}, {"email" => "bo@example.com"}.to_json)
29
+ user.save
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "correct use of ssl" do
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ require 'intercom'
2
+ require 'minitest/autorun'
3
+ require 'mocha'
4
+ require 'pry'
5
+ IRB = Pry
6
+
7
+ module Intercom
8
+ def self.mock_rest_client=(client)
9
+ @mock_rest_client = client
10
+ end
11
+
12
+ def self.execute_request(method, path, params = {}, headers= {}, payload = nil)
13
+ case method
14
+ when :get then @mock_rest_client.get(path, params)
15
+ when :post then @mock_rest_client.post(path, params, headers, payload)
16
+ end
17
+ end
18
+ end
19
+
20
+ def test_user
21
+ {
22
+ :user_id => 'mysql-id-from-customers-app for eg', # can request by this
23
+ :email => "bo@example.com", # can request by this
24
+ :session_count => 123, # can't be sent - but can get...
25
+ :created_at => 1323422442,
26
+ :last_request_at => 1323422442,
27
+ :name => "Joe Schmoe",
28
+ :social_accounts => {
29
+ "twitter" => [{"url" => "http://twitter.com/abc", "username" => "abc"}, {"username" => "abc2", "url" => "http://twitter.com/abc2"}],
30
+ "facebook" => [{"url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"}],
31
+ "quora" => [{"url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"}]
32
+ },
33
+ :custom_data => {"a" => 1, "b" => {"nested-hash" => ["ab", 12, {"deep" => "man"}]}}
34
+ }
35
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: intercom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben McRedmond
9
+ - Ciaran Lee
10
+ - Darragh Curran
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-02-16 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rest-client
18
+ requirement: &70210115859340 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70210115859340
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: &70210115840880 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *70210115840880
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ requirement: &70210115837980 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *70210115837980
49
+ - !ruby/object:Gem::Dependency
50
+ name: guard
51
+ requirement: &70210115837060 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70210115837060
60
+ - !ruby/object:Gem::Dependency
61
+ name: guard-minitest
62
+ requirement: &70210115835520 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *70210115835520
71
+ - !ruby/object:Gem::Dependency
72
+ name: pry
73
+ requirement: &70210115833560 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *70210115833560
82
+ - !ruby/object:Gem::Dependency
83
+ name: mocha
84
+ requirement: &70210115828200 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *70210115828200
93
+ description: Intercom is a customer relationship management and messaging tool for
94
+ web app owners. See http://intercom.io for more details.
95
+ email:
96
+ - ben@intercom.io
97
+ - ciaran@intercom.io
98
+ - darragh@intercom.io
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - Guardfile
106
+ - README.md
107
+ - Rakefile
108
+ - intercom.gemspec
109
+ - lib/intercom.rb
110
+ - lib/intercom/version.rb
111
+ - spec/intercom_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: http://intercom.io
114
+ licenses: []
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project: intercom
133
+ rubygems_version: 1.8.16
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Ruby bindings for the Intercom API
137
+ test_files:
138
+ - spec/intercom_spec.rb
139
+ - spec/spec_helper.rb