youroom_api 0.0.10 → 0.0.11

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.
@@ -20,8 +20,8 @@ module Youroom
20
20
  ShowAttachment.new(access_token, room_id, mutter_id, url).get
21
21
  end
22
22
 
23
- def get_all_timeline
24
- HomeTimeline.new(access_token, url).get
23
+ def get_all_timeline(params={ })
24
+ HomeTimeline.new(access_token, params, url).get
25
25
  end
26
26
 
27
27
  def get_unread_timeline
@@ -1,8 +1,21 @@
1
1
  module Youroom
2
2
  class HomeTimeline < Request
3
- # TODO: Request parameter feel bad
3
+ attr_reader :room_id, :since, :page, :flat, :read_state
4
+ QUERY_KEYS = %w[since page flat read_state]
5
+
6
+ def initialize(access_token, params={}, url=BASE_URL)
7
+ required_structure(params, Hash)
8
+ params.each { |k,v| self.instance_variable_set("@#{k}", v)}
9
+ super(access_token, url)
10
+ end
11
+
4
12
  def path
5
- File.join(url, '?format=json')
13
+ query_str = "&"
14
+ QUERY_KEYS.each do |query_key|
15
+ val = self.instance_variable_get("@#{query_key}")
16
+ query_str += "#{query_key}=#{val}&" if !val.nil?
17
+ end
18
+ File.join(url, '?format=json'+"#{query_str.chop}")
6
19
  end
7
20
  end
8
21
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
3
 
3
4
  describe Youroom::HomeTimeline do
@@ -14,17 +15,79 @@ describe Youroom::HomeTimeline do
14
15
 
15
16
  describe "when url is not original" do
16
17
  before do
17
- @client = Youroom::HomeTimeline.new(access_token, WW_URL)
18
+ @client = Youroom::HomeTimeline.new(access_token, { }, WW_URL)
18
19
  end
19
20
 
20
21
  subject { @client.path }
21
22
  it { should == File.join(@client.url, '?format=json')}
22
23
  end
24
+
25
+ describe "パラメータを設定する場合" do
26
+ context "sinceを設定する場合" do
27
+ before do
28
+ @client = Youroom::HomeTimeline.new(access_token, { :since => "hogehoge" })
29
+ end
30
+
31
+ subject { @client.path }
32
+
33
+ it "Queryパラメータにsinceが設定されていること" do
34
+ should == File.join(@client.url, '?format=json&since=hogehoge')
35
+ end
36
+ end
37
+
38
+ context "flatを設定する場合" do
39
+ before do
40
+ @client = Youroom::HomeTimeline.new(access_token, { :flat => "true" })
41
+ end
42
+
43
+ subject { @client.path }
44
+
45
+ it "Queryパラメータにflatが設定されていること" do
46
+ should == File.join(@client.url, '?format=json&flat=true')
47
+ end
48
+ end
49
+
50
+ context "pageを設定する場合" do
51
+ before do
52
+ @client = Youroom::HomeTimeline.new(access_token, { :page => 3 })
53
+ end
54
+
55
+ subject { @client.path }
56
+
57
+ it "Queryパラメータにpageが設定されていること" do
58
+ should == File.join(@client.url, '?format=json&page=3')
59
+ end
60
+ end
61
+
62
+ context "read_stateを設定する場合" do
63
+ before do
64
+ @client = Youroom::HomeTimeline.new(access_token, { :read_state => "unread" })
65
+ end
66
+
67
+ subject { @client.path }
68
+
69
+ it "Queryパラメータにread_stateが設定されていること" do
70
+ should == File.join(@client.url, '?format=json&read_state=unread')
71
+ end
72
+ end
73
+
74
+ context "複合オプションを設定した場合" do
75
+ before do
76
+ @client = Youroom::HomeTimeline.new(access_token, { :read_state => "unread", :page => 3, :flat => "true" })
77
+ end
78
+
79
+ subject { @client.path }
80
+
81
+ it "Queryパラメータに複合パラメータが設定されていること" do
82
+ should == File.join(@client.url, '?format=json&page=3&flat=true&read_state=unread')
83
+ end
84
+ end
85
+ end
23
86
  end
24
87
 
25
88
  describe "#call" do
26
89
  before do
27
- @client = Youroom::HomeTimeline.new(access_token, WW_URL)
90
+ @client = Youroom::HomeTimeline.new(access_token, { }, WW_URL)
28
91
  # dammy ww url
29
92
  @client.should_receive(:path).at_least(1).and_return("http://localhost:8083/all?format=json")
30
93
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 10
9
- version: 0.0.10
8
+ - 11
9
+ version: 0.0.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - pochi