forked from GeneralScripting/pipedrive-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Waldemar Kusnezow
committed
Nov 1, 2012
1 parent
6b83b7d
commit a4f5599
Showing
10 changed files
with
151 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,6 @@ pkg | |
|
||
# For rubinius: | ||
#*.rbc | ||
|
||
/.idea | ||
/.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
activesupport (3.2.8) | ||
i18n (~> 0.6) | ||
multi_json (~> 1.0) | ||
git (1.2.5) | ||
httparty (0.9.0) | ||
multi_json (~> 1.0) | ||
multi_xml | ||
i18n (0.6.1) | ||
jeweler (1.8.4) | ||
bundler (~> 1.0) | ||
git (>= 1.2.5) | ||
rake | ||
rdoc | ||
json (1.7.5) | ||
multi_json (1.3.6) | ||
multi_xml (0.5.1) | ||
rake (0.9.2.2) | ||
rdoc (3.12) | ||
json (~> 1.4) | ||
shoulda (3.3.2) | ||
shoulda-context (~> 1.0.1) | ||
shoulda-matchers (~> 1.4.1) | ||
shoulda-context (1.0.1) | ||
shoulda-matchers (1.4.1) | ||
activesupport (>= 3.0.0) | ||
simplecov (0.7.1) | ||
multi_json (~> 1.0) | ||
simplecov-html (~> 0.7.1) | ||
simplecov-html (0.7.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (>= 1.0.0) | ||
httparty | ||
jeweler (>= 1.8.4) | ||
rdoc (~> 3.12) | ||
shoulda | ||
simplecov |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.1 | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'pipedrive/base' | ||
require 'pipedrive/deal' | ||
|
||
module Pipedrive | ||
|
||
def self.authenticate(token) | ||
Base.authenticate(token) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'httparty' | ||
require 'ostruct' | ||
|
||
module Pipedrive | ||
|
||
# Globally set request headers | ||
HEADERS = { | ||
"User-Agent" => "Ruby.Pipedrive.Api", | ||
"Accept" => "application/json", | ||
"Content-Type" => "application/json" | ||
} | ||
|
||
# Base class for setting HTTParty configurations globally | ||
class Base < OpenStruct | ||
|
||
include HTTParty | ||
base_uri 'api.pipedrive.com/v1' | ||
headers HEADERS | ||
format :json | ||
|
||
# Sets the authentication credentials in a class variable. | ||
# | ||
# @param [String] email cl.ly email | ||
# @param [String] password cl.ly password | ||
# @return [Hash] authentication credentials | ||
def self.authenticate(token) | ||
self.default_params :api_token => token | ||
end | ||
|
||
# Examines a bad response and raises an approriate exception | ||
# | ||
# @param [HTTParty::Response] response | ||
def self.bad_response(response) | ||
if response.class == HTTParty::Response | ||
raise response.inspect | ||
raise ResponseError, response | ||
end | ||
raise StandardError, "Unkown error" | ||
end | ||
|
||
attr_reader :data | ||
|
||
# Create a new CloudApp::Base object. | ||
# | ||
# Only used internally | ||
# | ||
# @param [Hash] attributes | ||
# @return [CloudApp::Base] | ||
def initialize(attrs = {}) | ||
super(attrs['data']) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,25 @@ | ||
module Deal | ||
module Pipedrive | ||
|
||
class Deal < Base | ||
|
||
def self.create( opts = {} ) | ||
res = post "/deals", :body => opts | ||
if res.ok? | ||
Deal.new(res) | ||
else | ||
bad_response(res) | ||
end | ||
end | ||
|
||
def self.find(id) | ||
res = get "/deals/#{id}" | ||
if res.ok? | ||
Deal.new(res) | ||
else | ||
bad_response(res) | ||
end | ||
end | ||
|
||
end | ||
|
||
end |