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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 506a0f963ad30764a42e08c29054518eb119c5ca
4
- data.tar.gz: d67d55a6df42148286bfd569d159c932f5026f87
3
+ metadata.gz: 1b72366a2c43a2818f9958cf03f8fcf01b0173d5
4
+ data.tar.gz: 559646ba6b435275e6d2c3b1d3cce1aeafbc7b4f
5
5
  SHA512:
6
- metadata.gz: c33a02211be7877b90d04cb43e12bbc25c132db39b3a3003af1a96f5d5aae3ea4f81a02ef3725d33418ef64d352dbd03433e118724a029dc7ce9a5cdfdc6d5b2
7
- data.tar.gz: d457140afe746f53c17f3c8e4109b46499a84b9634783b22d4466ae68114672a8f107775b10c9c3e11c7ffa1f798be049648878621cc73335f82c32c556c9e59
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
- 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.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
- 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
-
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, DEFAULT_OPT)
11
- convert_response(get(ENDPOINT, opt))
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.uniq.compact.flatten, errors.compact.flatten]
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
- 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
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
@@ -1,3 +1,3 @@
1
1
  module EventsJp
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -28,13 +28,13 @@ end
28
28
 
29
29
  RSpec.configure do |config|
30
30
  config.before(:each) do
31
- stub_get("#{EventsJp::Atnd::ENDPOINT}?format=json&count=100&start=1", 'event/atnd.json')
32
- stub_get("#{EventsJp::Atnd::ENDPOINT}?format=json&count=100&start=1&keyword=Ruby", 'event/atnd_ruby.json')
33
- stub_get("#{EventsJp::Connpass::ENDPOINT}?order=2&count=100&start=1", 'event/connpass.json')
34
- stub_get("#{EventsJp::Connpass::ENDPOINT}?order=2&count=100&start=1&keyword=Ruby", 'event/connpass_ruby.json')
35
- stub_get("#{EventsJp::Doorkeeper::ENDPOINT}?locale=ja&sort=starts_at&page=1", 'event/doorkeeper.json')
36
- stub_get("#{EventsJp::Zusaar::ENDPOINT}?count=100&start=1", 'event/zusaar.json')
37
- stub_get("#{EventsJp::Zusaar::ENDPOINT}?count=100&start=1&keyword=Ruby", 'event/zusaar_ruby.json')
38
- stub_get("#{EventsJp::Zusaar::ENDPOINT}?count=100&start=1&keyword=Ruby", 'event/zusaar_ruby.json')
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: events_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - morizyun