events_jp 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/events_jp/event_object/atnd.rb +9 -15
- data/lib/events_jp/event_object/connpass.rb +9 -16
- data/lib/events_jp/event_object/doorkeeper.rb +13 -6
- data/lib/events_jp/event_object/event_object.rb +23 -0
- data/lib/events_jp/event_object/zusaar.rb +9 -15
- data/lib/events_jp/version.rb +1 -1
- data/spec/spec_helper.rb +8 -8
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1b72366a2c43a2818f9958cf03f8fcf01b0173d5
         | 
| 4 | 
            +
              data.tar.gz: 559646ba6b435275e6d2c3b1d3cce1aeafbc7b4f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5c4e07290fee2b796f61e5b65eccb04caa5c99e26e0cbe875ab345975030c7913ea416a41ddb3280cfb50e58fa17a6cf4bd879613dd40dd98dbc3314b09982bc
         | 
| 7 | 
            +
              data.tar.gz: 3ed18a91d2a21ecf8ad4bd407c01a4380f34e164b5ec35d93dbfba5f7ff24d5e2445559772ca8e4e61f217a0cccbfa3ad143f7c490069e0e32cef93bdd2c2811
         | 
| @@ -1,25 +1,19 @@ | |
| 1 1 | 
             
            module EventsJp
         | 
| 2 2 | 
             
              class Atnd < EventsJp::EventObject
         | 
| 3 | 
            -
                ENDPOINT = 'http://api.atnd.org/events/'.freeze
         | 
| 4 | 
            -
                DEFAULT_OPT = {format: 'json', count: 100}.freeze
         | 
| 5 3 |  | 
| 6 | 
            -
                 | 
| 7 | 
            -
                  results, errors = [], []
         | 
| 8 | 
            -
                  loop do
         | 
| 9 | 
            -
                    results, errors, has_response = access_wrapper(results, errors) do
         | 
| 10 | 
            -
                      opt = merged_option(keyword, results, DEFAULT_OPT)
         | 
| 11 | 
            -
                      convert_response(get(ENDPOINT, opt))
         | 
| 12 | 
            -
                    end
         | 
| 13 | 
            -
                    break if finish_get?(results, has_response, limit)
         | 
| 14 | 
            -
                    sleep(1)
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  return [results.uniq.compact.flatten, errors.compact.flatten]
         | 
| 18 | 
            -
                end
         | 
| 4 | 
            +
                private
         | 
| 19 5 |  | 
| 20 6 | 
             
                def self.convert_response(json_str)
         | 
| 21 7 | 
             
                  e = Hashie::Mash.new(JSON.parse(json_str)).events
         | 
| 22 8 | 
             
                  e.map { |_| to_basic_hash(_.event) }
         | 
| 23 9 | 
             
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def self.endpoint
         | 
| 12 | 
            +
                  'http://api.atnd.org/events/'
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def self.default_opt
         | 
| 16 | 
            +
                  {format: 'json', count: 100}
         | 
| 17 | 
            +
                end
         | 
| 24 18 | 
             
              end
         | 
| 25 19 | 
             
            end
         | 
| @@ -1,26 +1,19 @@ | |
| 1 1 | 
             
            module EventsJp
         | 
| 2 2 | 
             
              class Connpass < EventsJp::EventObject
         | 
| 3 | 
            -
                ENDPOINT = 'http://connpass.com/api/v1/event/'.freeze
         | 
| 4 | 
            -
                DEFAULT_OPT = {order: 2, count: 100}.freeze
         | 
| 5 3 |  | 
| 6 | 
            -
                 | 
| 7 | 
            -
                  results, errors = [], []
         | 
| 8 | 
            -
                  loop do
         | 
| 9 | 
            -
                    results, errors, has_response = access_wrapper(results, errors) do
         | 
| 10 | 
            -
                      opt = merged_option(keyword, results, DEFAULT_OPT)
         | 
| 11 | 
            -
                      convert_response(get(ENDPOINT, opt))
         | 
| 12 | 
            -
                    end
         | 
| 13 | 
            -
                    break if finish_get?(results, has_response, limit)
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                    sleep(1)
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                  return [results.uniq.compact.flatten, errors.compact.flatten]
         | 
| 19 | 
            -
                end
         | 
| 4 | 
            +
                private
         | 
| 20 5 |  | 
| 21 6 | 
             
                def self.convert_response(json_str)
         | 
| 22 7 | 
             
                  e = Hashie::Mash.new(JSON.parse(json_str)).events
         | 
| 23 8 | 
             
                  e.map { |_| to_basic_hash(_) }
         | 
| 24 9 | 
             
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def self.endpoint
         | 
| 12 | 
            +
                  'http://connpass.com/api/v1/event/'
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def self.default_opt
         | 
| 16 | 
            +
                  {order: 2, count: 100}
         | 
| 17 | 
            +
                end
         | 
| 25 18 | 
             
              end
         | 
| 26 19 | 
             
            end
         | 
| @@ -1,22 +1,21 @@ | |
| 1 1 | 
             
            module EventsJp
         | 
| 2 2 | 
             
              class Doorkeeper < EventsJp::EventObject
         | 
| 3 | 
            -
                ENDPOINT = 'http://api.doorkeeper.jp/events'.freeze
         | 
| 4 | 
            -
                DEFAULT_OPT = {locale: 'ja', sort: 'starts_at'}.freeze
         | 
| 5 | 
            -
             | 
| 6 3 | 
             
                def self.get_events(keyword: nil, limit: nil)
         | 
| 7 4 | 
             
                  results, errors = [], []
         | 
| 8 5 | 
             
                  1.upto(1000) do |page|
         | 
| 9 6 | 
             
                    results, errors, has_response = access_wrapper(results, errors) do
         | 
| 10 | 
            -
                      opt = merged_option(page,  | 
| 11 | 
            -
                      convert_response(get( | 
| 7 | 
            +
                      opt = merged_option(page, default_opt)
         | 
| 8 | 
            +
                      convert_response(get(endpoint, opt))
         | 
| 12 9 | 
             
                    end
         | 
| 13 10 | 
             
                    break if finish_get?(results, has_response, limit)
         | 
| 14 11 | 
             
                    sleep(1)
         | 
| 15 12 | 
             
                  end
         | 
| 16 13 |  | 
| 17 | 
            -
                  return [results | 
| 14 | 
            +
                  return [results, errors]
         | 
| 18 15 | 
             
                end
         | 
| 19 16 |  | 
| 17 | 
            +
                private
         | 
| 18 | 
            +
             | 
| 20 19 | 
             
                def self.merged_option(page, option)
         | 
| 21 20 | 
             
                  opt = option.dup
         | 
| 22 21 | 
             
                  opt.merge({page: page})
         | 
| @@ -45,5 +44,13 @@ module EventsJp | |
| 45 44 | 
             
                                     accepted:    h[:participants],
         | 
| 46 45 | 
             
                                     waiting:     h[:waitlisted] })
         | 
| 47 46 | 
             
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def self.endpoint
         | 
| 49 | 
            +
                  'http://api.doorkeeper.jp/events'
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def self.default_opt
         | 
| 53 | 
            +
                  {locale: 'ja', sort: 'starts_at'}
         | 
| 54 | 
            +
                end
         | 
| 48 55 | 
             
              end
         | 
| 49 56 | 
             
            end
         | 
| @@ -3,6 +3,22 @@ module EventsJp | |
| 3 3 | 
             
                class ImplementationException < Exception; end
         | 
| 4 4 | 
             
                extend EventsJp::Connection
         | 
| 5 5 |  | 
| 6 | 
            +
                def self.get_events(keyword: nil, limit: nil)
         | 
| 7 | 
            +
                  results, errors = [], []
         | 
| 8 | 
            +
                  loop do
         | 
| 9 | 
            +
                    results, errors, has_response = access_wrapper(results, errors) do
         | 
| 10 | 
            +
                      opt = merged_option(keyword, results, default_opt)
         | 
| 11 | 
            +
                      convert_response(get(endpoint, opt))
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
                    break if finish_get?(results, has_response, limit)
         | 
| 14 | 
            +
                    sleep(1)
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  return [results, errors]
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                private
         | 
| 21 | 
            +
             | 
| 6 22 | 
             
                def self.access_wrapper(results, errors, &block)
         | 
| 7 23 | 
             
                  results << (tmp = block.call)
         | 
| 8 24 | 
             
                  has_response = (tmp.count >= 1)
         | 
| @@ -48,5 +64,12 @@ module EventsJp | |
| 48 64 | 
             
                def self.parse_datetime(dt)
         | 
| 49 65 | 
             
                  dt ? DateTime.parse(dt) : nil
         | 
| 50 66 | 
             
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                # インターフェース
         | 
| 69 | 
            +
                def self.endpoint
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                def self.default_opt
         | 
| 73 | 
            +
                end
         | 
| 51 74 | 
             
              end
         | 
| 52 75 | 
             
            end
         | 
| @@ -1,25 +1,19 @@ | |
| 1 1 | 
             
            module EventsJp
         | 
| 2 2 | 
             
              class Zusaar < EventsJp::EventObject
         | 
| 3 | 
            -
                ENDPOINT = 'http://www.zusaar.com/api/event/'.freeze
         | 
| 4 | 
            -
                DEFAULT_OPT = {count: 100}.freeze
         | 
| 5 3 |  | 
| 6 | 
            -
                 | 
| 7 | 
            -
                  results, errors = [], []
         | 
| 8 | 
            -
                  loop do
         | 
| 9 | 
            -
                    results, errors, has_response = access_wrapper(results, errors) do
         | 
| 10 | 
            -
                      opt = merged_option(keyword, results, DEFAULT_OPT)
         | 
| 11 | 
            -
                      convert_response(get(ENDPOINT, opt))
         | 
| 12 | 
            -
                    end
         | 
| 13 | 
            -
                    break if finish_get?(results, has_response, limit)
         | 
| 14 | 
            -
                    sleep(1)
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  return [results, errors]
         | 
| 18 | 
            -
                end
         | 
| 4 | 
            +
                private
         | 
| 19 5 |  | 
| 20 6 | 
             
                def self.convert_response(json_str)
         | 
| 21 7 | 
             
                  e = Hashie::Mash.new(JSON.parse(json_str)).event
         | 
| 22 8 | 
             
                  e.map{ |_| to_basic_hash(_) }
         | 
| 23 9 | 
             
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def self.endpoint
         | 
| 12 | 
            +
                  'http://www.zusaar.com/api/event/'
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def self.default_opt
         | 
| 16 | 
            +
                  {count: 100}
         | 
| 17 | 
            +
                end
         | 
| 24 18 | 
             
              end
         | 
| 25 19 | 
             
            end
         | 
    
        data/lib/events_jp/version.rb
    CHANGED
    
    
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -28,13 +28,13 @@ end | |
| 28 28 |  | 
| 29 29 | 
             
            RSpec.configure do |config|
         | 
| 30 30 | 
             
             config.before(:each) do
         | 
| 31 | 
            -
               stub_get("#{EventsJp::Atnd | 
| 32 | 
            -
               stub_get("#{EventsJp::Atnd | 
| 33 | 
            -
               stub_get("#{EventsJp::Connpass | 
| 34 | 
            -
               stub_get("#{EventsJp::Connpass | 
| 35 | 
            -
               stub_get("#{EventsJp::Doorkeeper | 
| 36 | 
            -
               stub_get("#{EventsJp::Zusaar | 
| 37 | 
            -
               stub_get("#{EventsJp::Zusaar | 
| 38 | 
            -
               stub_get("#{EventsJp::Zusaar | 
| 31 | 
            +
               stub_get("#{EventsJp::Atnd.__send__(:endpoint)}?format=json&count=100&start=1", 'event/atnd.json')
         | 
| 32 | 
            +
               stub_get("#{EventsJp::Atnd.__send__(:endpoint)}?format=json&count=100&start=1&keyword=Ruby", 'event/atnd_ruby.json')
         | 
| 33 | 
            +
               stub_get("#{EventsJp::Connpass.__send__(:endpoint)}?order=2&count=100&start=1", 'event/connpass.json')
         | 
| 34 | 
            +
               stub_get("#{EventsJp::Connpass.__send__(:endpoint)}?order=2&count=100&start=1&keyword=Ruby", 'event/connpass_ruby.json')
         | 
| 35 | 
            +
               stub_get("#{EventsJp::Doorkeeper.__send__(:endpoint)}?locale=ja&sort=starts_at&page=1", 'event/doorkeeper.json')
         | 
| 36 | 
            +
               stub_get("#{EventsJp::Zusaar.__send__(:endpoint)}?count=100&start=1", 'event/zusaar.json')
         | 
| 37 | 
            +
               stub_get("#{EventsJp::Zusaar.__send__(:endpoint)}?count=100&start=1&keyword=Ruby", 'event/zusaar_ruby.json')
         | 
| 38 | 
            +
               stub_get("#{EventsJp::Zusaar.__send__(:endpoint)}?count=100&start=1&keyword=Ruby", 'event/zusaar_ruby.json')
         | 
| 39 39 | 
             
              end
         | 
| 40 40 | 
             
            end
         |