metaweblog 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 430757e72fb340b24d2589db4dde0c0170b429eb
4
+ data.tar.gz: eca57d56e475dc18a103298f7b0814860e72b61f
5
+ SHA512:
6
+ metadata.gz: 6b122aba4f970ed65200b0951145e4a80b846ecabc633b1a486578b1a53447b1b8150b6a1d3254b5bfcde4adb601b7c34d09f0e8f9205db1f5b787db2c125b94
7
+ data.tar.gz: 0dfae078d8da9c52f405b642648d29170716995aa904cccced4f1a37b842ec810cdd7e5baa848982014b6fa739154091d4657957747031b28260ca4899dee633
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ -fd
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.2
@@ -0,0 +1,5 @@
1
+ # 0.2.0 (2014-05-25)
2
+
3
+ * Refactor `MetaWeblog::Post`
4
+ * Support `MetaWeblog::Post#pubDate` and `MetaWeblog::Post#pubDate=`
5
+ * Specify `Accept-Encoding: identity` as workaround to the [xmlrpc's bug](https://bugs.ruby-lang.org/issues/8182) for Ruby 2.0.0 or later
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require 'metaweblog'
4
+
5
+ blog_id, username, password = *(ARGV.dup.first(3))
6
+
7
+ client = MetaWeblog::Client.new("http://blog.fc2.com/xmlrpc.php",
8
+ blog_id,
9
+ username, password)
10
+
11
+ client.recent_posts.each do |post|
12
+ puts post
13
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'metaweblog'
4
+
5
+ blog_id, username, password = *(ARGV.dup.first(3))
6
+
7
+ entry = MetaWeblog::Post.new({
8
+ title: "Hello, MetaWeblog #{MetaWeblog::VERSION}",
9
+ description: 'This entry has been posted by metaweblog gem.',
10
+ pubDate: Time.new(2009, 4, 1)
11
+ })
12
+
13
+ client = MetaWeblog::Client.new("http://blog.fc2.com/xmlrpc.php",
14
+ blog_id,
15
+ username, password)
16
+
17
+ puts client.post(entry)
@@ -1,11 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'metaweblog/post'
3
4
  require 'xmlrpc/client'
4
5
 
5
6
  module MetaWeblog
6
- POST_MEMBERS = [:title, :link, :description]
7
- Post = Struct.new(*POST_MEMBERS)
8
-
9
7
  class Client
10
8
  attr_reader :uri, :proxy, :blog_id, :username, :password, :client
11
9
 
@@ -16,6 +14,7 @@ module MetaWeblog
16
14
  @username = username
17
15
  @password = password
18
16
  @client = XMLRPC::Client.new2(@uri, @proxy)
17
+ @client.http_header_extra = { 'Accept-Encoding' => 'identity' }
19
18
  end
20
19
 
21
20
  def get(post_id)
@@ -23,11 +22,11 @@ module MetaWeblog
23
22
  end
24
23
 
25
24
  def post(post, publish=true)
26
- client.call('metaWeblog.newPost', blog_id, username, password, post, publish)
25
+ client.call('metaWeblog.newPost', blog_id, username, password, post.to_h, publish)
27
26
  end
28
27
 
29
28
  def edit(post_id, post, publish=true)
30
- client.call('metaWeblog.editPost', post_id, username, password, post, publish)
29
+ client.call('metaWeblog.editPost', post_id, username, password, post.to_h, publish)
31
30
  end
32
31
 
33
32
  def recent_posts(n=10)
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ module MetaWeblog
4
+
5
+ class Post
6
+ def self.members
7
+ [:title, :link, :description, :pubDate]
8
+ end
9
+
10
+ def initialize(*args)
11
+ @data = {}
12
+
13
+ if args.length == 1 && args.last.is_a?(Hash)
14
+ h = args.last
15
+ data = self.class.members.map { |m| (h[m] || h[m.to_s]) }
16
+ else
17
+ data = args
18
+ end
19
+ self.class.members.each_with_index do |member, i|
20
+ self.__send__ "#{member}=", data[i] if data[i]
21
+ end
22
+ end
23
+
24
+ def [](m)
25
+ @data[m]
26
+ end
27
+
28
+ def to_h
29
+ @data.dup
30
+ end
31
+
32
+ members.each do |member|
33
+ define_method member do
34
+ @data[member]
35
+ end
36
+
37
+ define_method "#{member}=" do |val|
38
+ @data[member] = val
39
+ end
40
+ end
41
+
42
+ def pub_date=(pub_date)
43
+ @data[:pubDate] = case pub_date
44
+ when String then Time.parse(pub_date)
45
+ when Time, DateTime then pub_date
46
+ else
47
+ raise ArgumentError, "The argument is not String, Time and DateTime."
48
+ end
49
+ end
50
+ alias :pubDate= :pub_date=
51
+
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module MetaWeblog
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,6 +6,7 @@ require 'metaweblog/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "metaweblog"
8
8
  spec.version = MetaWeblog::VERSION
9
+ spec.version = "#{spec.version}.pre#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
9
10
  spec.authors = ["Tatsuya Sato"]
10
11
  spec.email = ["satoryu.1981@gmail.com"]
11
12
  spec.description = <<-DESC
@@ -5,29 +5,36 @@ require 'spec_helper'
5
5
  describe MetaWeblog::Client do
6
6
  before do
7
7
  @client = MetaWeblog::Client.new('http://blog.example.com/xmlrpc',
8
- 'blog_id',
9
- 'username',
10
- 'password')
11
- @xml_client = stub()
8
+ 'blog_id', 'username', 'password')
9
+ @xml_client = double()
12
10
  @client.instance_variable_set(:@client, @xml_client)
13
11
  end
12
+
14
13
  describe "#post" do
15
- let(:expected_post) { MetaWeblog::Post.new('title', 'hogehoge') }
14
+ let(:expected_post) do
15
+ { title: 'title', description: 'hogehoge' }
16
+ end
17
+ let(:post) { MetaWeblog::Post.new(expected_post) }
18
+
16
19
  before do
17
20
  @xml_client.should_receive(:call).with('metaWeblog.newPost',
18
21
  'blog_id',
19
22
  'username', 'password',
20
23
  expected_post, true)
21
24
  end
25
+
22
26
  it do
23
- expect { @client.post(expected_post) }.not_to raise_error
27
+ expect { @client.post(post) }.not_to raise_error
24
28
  end
25
29
  end
30
+
26
31
  describe "#get" do
27
32
  let(:post_id) { 12345 }
33
+
28
34
  before do
29
35
  @xml_client.should_receive(:call).with('metaWeblog.getPost', post_id, 'username', 'password')
30
36
  end
37
+
31
38
  it do
32
39
  expect { @client.get(post_id) }.not_to raise_error
33
40
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe MetaWeblog::Post do
4
+ let(:post) { MetaWeblog::Post.new(*args) }
5
+
6
+ describe '#initialize' do
7
+ context 'Given an array of values' do
8
+ let(:args) do
9
+ [ 'title', 'http://blog.example.com/1234', 'desc' ]
10
+ end
11
+
12
+ specify '' do
13
+ expect(post.title).to eq('title')
14
+ expect(post.link).to eq('http://blog.example.com/1234')
15
+ expect(post.description).to eq('desc')
16
+ end
17
+ end
18
+
19
+ context 'Given only a hash' do
20
+ let(:args) do
21
+ [{ :title => 'Hello', 'description' => 'This is blog', :extra => 'not defined' }]
22
+ end
23
+
24
+ specify 'should assign values for members' do
25
+ expect(post[:title]).to eq(args[0][:title])
26
+ expect(post[:description]).to eq(args[0]['description'])
27
+ expect(post[:link]).to be_nil
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#pubDate' do
33
+ let(:args) { ['title', nil, nil, pubDate ] }
34
+
35
+ context 'Given as String' do
36
+ let(:pubDate) { 'Wed, 29 Jul 1981 21:16:00 +0900' }
37
+
38
+ specify 'should be Time object' do
39
+ expect(post.pubDate).to be_a(Time)
40
+ end
41
+ end
42
+
43
+ context 'Given as Time object' do
44
+ let(:pubDate) { Time.now }
45
+
46
+ specify 'should be Time object' do
47
+ expect(post.pubDate).to eq(pubDate)
48
+ end
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,109 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metaweblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tatsuya Sato
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2014-05-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '2.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '2.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
- description: ! " Ruby client for metaWeblog API.\n This gem makes it easier
63
- for developers to talk with your Blog supporting\n metaWeblog API. \n This
64
- gem only depends on REXML provided as one of Ruby's standard lib. \n"
55
+ description: " Ruby client for metaWeblog API.\n This gem makes it easier for
56
+ developers to talk with your Blog supporting\n metaWeblog API. \n This gem
57
+ only depends on REXML provided as one of Ruby's standard lib. \n"
65
58
  email:
66
59
  - satoryu.1981@gmail.com
67
60
  executables: []
68
61
  extensions: []
69
62
  extra_rdoc_files: []
70
63
  files:
71
- - .gitignore
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - CHANGELOG.md
72
68
  - Gemfile
73
69
  - LICENSE.txt
74
70
  - README.md
75
71
  - Rakefile
72
+ - examples/get_posts.rb
73
+ - examples/publish_new_entry.rb
76
74
  - lib/metaweblog.rb
77
75
  - lib/metaweblog/client.rb
76
+ - lib/metaweblog/post.rb
78
77
  - lib/metaweblog/version.rb
79
78
  - metaweblog.gemspec
80
79
  - spec/metaweblog/client_spec.rb
80
+ - spec/metaweblog/post_spec.rb
81
81
  - spec/spec_helper.rb
82
82
  homepage: http://github.com/satoryu/metaweblog
83
83
  licenses:
84
84
  - MIT
85
+ metadata: {}
85
86
  post_install_message:
86
87
  rdoc_options: []
87
88
  require_paths:
88
89
  - lib
89
90
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
91
  requirements:
92
- - - ! '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 1.9.3
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
96
  requirements:
98
- - - ! '>='
97
+ - - ">="
99
98
  - !ruby/object:Gem::Version
100
99
  version: '0'
101
100
  requirements: []
102
101
  rubyforge_project:
103
- rubygems_version: 1.8.25
102
+ rubygems_version: 2.2.0
104
103
  signing_key:
105
- specification_version: 3
104
+ specification_version: 4
106
105
  summary: Ruby client for metaWeblog API.
107
106
  test_files:
108
107
  - spec/metaweblog/client_spec.rb
108
+ - spec/metaweblog/post_spec.rb
109
109
  - spec/spec_helper.rb