Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Waldemar Kusnezow committed Nov 1, 2012
1 parent 6b83b7d commit a4f5599
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ pkg

# For rubinius:
#*.rbc

/.idea
/.rvmrc
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ source "http://rubygems.org"
# Example:
# gem "activesupport", ">= 2.3.5"

gem 'httparty'

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.8.4"
gem "rcov", ">= 0"
gem "bundler", ">= 1.0.0"
gem "jeweler", ">= 1.8.4"
gem "simplecov", ">= 0"
end
43 changes: 43 additions & 0 deletions Gemfile.lock
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
20 changes: 0 additions & 20 deletions LICENSE.txt

This file was deleted.

16 changes: 11 additions & 5 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
= pipedrive-rails

Description goes here.
== Installation

gem install pipedrive-rails

== Usage

require 'pipedrive-rails'
Pipedrive.authenticate( YOUR_API_TOKEN )
Pipedrive::Deal.find( DEAL_ID )

== Contributing to pipedrive-rails

Expand All @@ -12,8 +20,6 @@ Description goes here.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2012 Waldemar Kusnezow. See LICENSE.txt for
further details.
== License

This gem is released under the {MIT License}[http://www.opensource.org/licenses/MIT].
8 changes: 0 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end

require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
test.rcov_opts << '--exclude "gems/*"'
end

task :default => :test

require 'rdoc/task'
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.1.0
10 changes: 10 additions & 0 deletions lib/pipedrive-rails.rb
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
55 changes: 55 additions & 0 deletions lib/pipedrive/base.rb
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
24 changes: 23 additions & 1 deletion lib/pipedrive/deal.rb
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

0 comments on commit a4f5599

Please sign in to comment.