freshmaker 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ require 'yaml'
2
+ AUTH = YAML::load(File.open 'conf/auth.yml')
3
+
4
+ require 'freshmaker/client'
5
+ require 'freshmaker/ticket_proxy'
6
+ require 'freshmaker/user_proxy'
7
+ require 'freshmaker/version'
8
+
9
+ module Freshmaker
10
+ class << self
11
+ attr_writer :email, :password
12
+
13
+ def new
14
+ Freshmaker::Client.new(@email, @password)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'httparty'
2
+
3
+ module Freshmaker
4
+ class Client
5
+ include HTTParty
6
+
7
+ base_uri AUTH['url']
8
+
9
+ def initialize(email, password)
10
+ @auth = { username: email, password: password }
11
+ end
12
+
13
+ def get(path, options={})
14
+ options.merge!({ basic_auth: @auth })
15
+ self.class.get("#{path}.xml?", options)
16
+ end
17
+
18
+ def users
19
+ Freshmaker::UserProxy.new(self)
20
+ end
21
+
22
+ def tickets
23
+ Freshmaker::TicketProxy.new(self)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Freshmaker
2
+ class TicketProxy
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def get(email)
8
+ response = @client.get('/helpdesk/tickets/user_ticket', query: { email: email })
9
+ response['helpdesk_tickets'] || []
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module Freshmaker
2
+ class UserProxy
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def all
8
+ all = []
9
+ page = 1
10
+
11
+ begin
12
+ users = get(page: page)
13
+ all += users
14
+ page += 1
15
+ end while users.present?
16
+
17
+ all
18
+ end
19
+
20
+ def get(params={})
21
+ response = @client.get('/contacts', query: params)
22
+ response['users'] || []
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Freshmaker
2
+ VERSION = '0.1'
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freshmaker::Client do
4
+ subject { Freshmaker::Client }
5
+
6
+ let(:email) { AUTH['email'] }
7
+ let(:password) { AUTH['password'] }
8
+ let(:client) { Freshmaker::Client.new(email, password) }
9
+
10
+ describe '#initialize' do
11
+ context 'authorization' do
12
+ subject { client.instance_variable_get(:@auth) }
13
+
14
+ it { should be_a(Hash) }
15
+ its([:username]) { should eql(email) }
16
+ its([:password]) { should eql(password) }
17
+ end
18
+ end
19
+
20
+ describe '#get' do
21
+ it 'should return an HTTParty response' do
22
+ response = client.get('/contacts')
23
+ response.class.should be(HTTParty::Response)
24
+ end
25
+ end
26
+
27
+ describe '#users' do
28
+ subject { client.users }
29
+ it { should be_an_instance_of(Freshmaker::UserProxy) }
30
+ end
31
+
32
+ describe '#tickets' do
33
+ subject { client.tickets}
34
+ it { should be_an_instance_of(Freshmaker::TicketProxy) }
35
+ end
36
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freshmaker::TicketProxy do
4
+ let(:fd_email) { AUTH['email'] }
5
+ let(:fd_password) { AUTH['password'] }
6
+ let(:client) { Freshmaker::Client.new(fd_email, fd_password) }
7
+
8
+ let(:ticket_proxy) { Freshmaker::TicketProxy.new(client) }
9
+
10
+ describe '.initialize' do
11
+ it 'should set the client' do
12
+ ticket_proxy.instance_variable_get(:@client).should eql(client)
13
+ end
14
+ end
15
+
16
+ describe '.get' do
17
+ let(:email) { 'tal@safran.com' }
18
+
19
+ context 'gets a response' do
20
+ before(:all) do
21
+ @tickets = ticket_proxy.get(email)
22
+ end
23
+
24
+ it 'should return a response' do
25
+ @tickets.should be
26
+ end
27
+
28
+ it 'should be an array of tickets' do
29
+ @tickets.should be_an(Array)
30
+ end
31
+
32
+ it 'should have all the fields we want' do
33
+ @tickets.each do |ticket|
34
+ ticket.should have_key('description')
35
+ ticket.should have_key('subject')
36
+ ticket.should have_key('due_by')
37
+ ticket.should have_key('display_id')
38
+ ticket.should have_key('requester_id')
39
+ ticket.should have_key('responder_id')
40
+ ticket.should have_key('created_at')
41
+ ticket.should have_key('updated_at')
42
+
43
+ ticket['notes'].each do |note|
44
+ note.should have_key('body')
45
+ note.should have_key('incoming')
46
+ note.should have_key('private')
47
+ note.should have_key('id')
48
+ note.should have_key('user_id')
49
+ note.should have_key('created_at')
50
+ note.should have_key('updated_at')
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ context 'empty response' do
57
+ it 'should return an empty array' do
58
+ Freshmaker::Client.stub(:get).and_return({})
59
+ ticket_proxy.get(email).should == []
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freshmaker::UserProxy do
4
+ let(:fd_email) { AUTH['email'] }
5
+ let(:fd_password) { AUTH['password'] }
6
+ let(:client) { Freshmaker::Client.new(fd_email, fd_password) }
7
+
8
+ let(:user_proxy) { Freshmaker::UserProxy.new(client) }
9
+
10
+ describe '.initialize' do
11
+ it 'should set the client' do
12
+ user_proxy.instance_variable_get(:@client).should eql(client)
13
+ end
14
+ end
15
+
16
+ describe '.get' do
17
+ let(:email) { 'tal@safran.com' }
18
+
19
+ context 'gets a response' do
20
+ before(:all) do
21
+ @users = user_proxy.get
22
+ end
23
+
24
+ it 'should return a response' do
25
+ @users.should be
26
+ end
27
+
28
+ it 'should be an array' do
29
+ @users.should be_an(Array)
30
+ end
31
+
32
+ it 'should have at most 10 users on a page' do
33
+ @users.count.should <= 10
34
+ end
35
+
36
+ context 'each user' do
37
+ it 'should have all the attributes we need' do
38
+ @users.each do |user|
39
+ user['name'].should be
40
+ user['id'].should be
41
+ user['email'].should be
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'empty response' do
48
+ it 'should return an empty array' do
49
+ Freshmaker::Client.stub(:get).and_return({})
50
+ user_proxy.get.should == []
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Freshmaker do
4
+ describe '#new' do
5
+ subject { Freshmaker.new }
6
+ it { should be_an_instance_of(Freshmaker::Client) }
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'freshmaker'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freshmaker
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tal Safran
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70289799300140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70289799300140
25
+ description: A simple API wrapper for Freshmaker.
26
+ email: tal@talsafran.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - lib/freshmaker.rb
32
+ - lib/freshmaker/client.rb
33
+ - lib/freshmaker/ticket_proxy.rb
34
+ - lib/freshmaker/user_proxy.rb
35
+ - lib/freshmaker/version.rb
36
+ - spec/freshmaker/client_spec.rb
37
+ - spec/freshmaker/ticket_proxy_spec.rb
38
+ - spec/freshmaker/user_proxy_spec.rb
39
+ - spec/freshmaker_spec.rb
40
+ - spec/spec_helper.rb
41
+ homepage: http://github.com/talsafran/freshmaker
42
+ licenses:
43
+ - MIT
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.17
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Freshmaker – A simple API wrapper for Freshmaker.
66
+ test_files: []