GeneralScripting / pipedrive-ruby

32 stars 148 forks source link

Maintained Fork? #48

Open Meekohi opened 7 years ago

Meekohi commented 7 years ago

Hey this project has pretty clearly been abandoned by the owner based on the number of ignored Pull Requests for simple things like the now mandatory HTTPS endpoints. Does someone want to step up and declare their fork as an "official" descendant fork, with a promise to maintain it going forward (with help from the community, of course)?

TrevorHinesley commented 7 years ago

This fork seems like the way to go if @VincentJaouen is willing to maintain:

https://github.com/VincentJaouen/pipedrive-ruby

VincentJaouen commented 7 years ago

Hey, sure I'll be happy to maintain the project

januszm commented 6 years ago

@VincentJaouen are you able to push new releases of this gem to rubygems.org ?

x-yuri commented 4 years ago

Yeah, at least updates are working with VincentJaouen/pipedrive-ruby. @VincentJaouen you could update the Installation section:

gem 'pipedrive-ruby', github: 'VincentJaouen/pipedrive-ruby'

UPD And with the following patch:

module Pipedrive
  class Base < OpenStruct
    class << self
      def all(response = nil, options={},get_absolutely_all=false)
        res = response ? response.call(options) : get(resource_path, options)
        if res.ok?
          data = res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
pp data.map { |f| f.name }
          if get_absolutely_all && res['additional_data']['pagination'] && res['additional_data']['pagination'] && res['additional_data']['pagination']['more_items_in_collection']
            options[:query] = options[:query].merge({:start => res['additional_data']['pagination']['next_start']})
            data += self.all(response,options,true)
          end
          data
        else
          bad_response(res,attrs)
        end
      end
    end
  end

  class Deal < Base
    def files(options = {}, get_absolutely_all=false)
      File.all(->(options) { get("#{resource_path}/#{id}/files", options) }, options, get_absolutely_all)
    end
  end
end

you can obtain all the files:

Pipedrive::Deal.find(id).files({}, true)

Although it's best to do something along the lines of what pipedrive.rb does.

E.g.:

module Pipedrive
  class Deal < Base
    def each_file
      return to_enum(:each_file) unless block_given?
      follow_pagination { |f| yield f }
    end

    def follow_pagination
      options = {query: {start: 0, limit: 1}}
      loop do
        res = get("#{resource_path}/#{id}/files", options)
        return bad_response(res) unless res.ok?
        res['data'].each do |f|
          yield File.new(f)
        end
        break unless res.dig('additional_data', 'pagination', 'more_items_in_collection')
        options[:query][:start] = res.dig('additional_data', 'pagination', 'next_start')
      end
    end
  end
end

Pipedrive::Deal.find(id).each_file do |f|
  puts f.name
end

bug at base.rb: attrs -> options