hatenagroup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWFjZWYzZjAxOTg2ZGZjYTIyZDgzMWE1MDcyMzBmMDFlY2RiMDYzYg==
5
+ data.tar.gz: !binary |-
6
+ ZTk0ZTE0ZjA3MjE5OGIzYThlNmU1OGY1NTFjMzk4NjQyN2U1NDA2OQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NWMwNmY2NzAxMjlhYzdkMjFjMjI3MmZhNDMzNGRiZmZhYTYyNDYyZTZjMmI0
10
+ Yzk3NDEyZDFjMWUyMjc3NGRjM2U1ZGJhMDY1YjI2NzYxMjJjMWRiYzg4Mzll
11
+ ZjYyNWRlMjVmYTdlMzcyN2Q0OWJlMGI1ZjA5NjAyN2I5OTRmMDU=
12
+ data.tar.gz: !binary |-
13
+ YzQxODc2MTRiYzQwMjNiNDUxMDA0MWQ0ZTU3MDZhMzM5YWNhZWVlYTM5YjJm
14
+ NjIzNzNkMTQzYzE2MmIxOWM4YjQzMjFlODQ3ZjQwYmEwZjNhYWFiODliODNm
15
+ YTU2NmU5NjFmOGRiN2Y4ZDQ5ODFmZjYxMWE5N2MwMDM1MmZjMjY=
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/fixtures/vcr/
10
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,28 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - "2.3.0"
5
+ - "2.2"
6
+ - "2.1"
7
+ - "2.0"
8
+ - "1.9"
9
+
10
+ sudo: false
11
+
12
+ script:
13
+ - bundle exec rake spec
14
+
15
+ cache:
16
+ bundler: true
17
+
18
+ deploy:
19
+ provider: rubygems
20
+ api_key:
21
+ master:
22
+ secure: "RD/T3tK6Vmar5vFDDbaV2GdSF/04cAMDqVCtVGZjiCkPPVJCj9NdUVJhKGGg//AQ9fY4+ZXeZjeThJrzv6gK4TjnvAIhMmZA+YMdtV77tDwaeRT2+UZmYtrGiymziWPDOMPNf+GFdNo8Hx4oKhtRXLA1aeHK0OIW2uJwyLmouXxv0cw29fYTtAOkxlBcRv/hXJaLuVDs1RMYBQmIwZlXiAA2vgNbnFFO5hvQwAtMx+7r+0cxGS56e2tC99vQo572t49ePPkjv6HZKd3zd6jWpVWBWS8b5ylPT1poEIpinBJl58kI8+i/r0M7bs376Y0LgK1WV/Jk6gboixYAI4iQdFFSF99vyw9HCBP2547unnqK5dTQW6smVQyy3NSfGLjVY5teqVVB9hacC+neAtYkAy789gjWu4mr0bMGH83sKnS6nexavW51tdqRbqoqFSX/S7r1FKgBKUhLa5VhGuSgsiowtCi0SnahnJhEn7TRjGtoBt8W/jZMbBahftsiT9GRXFz0EzUiWcNxuWB1SFJZ6r1F+0/RTs4fPLUxCJKExdLX8bRsKLr1UKJEFXLgxQJ6ay9dRIQJSQus0YdYwocRYFTQVhUwEhGpvCFdI+tPdEXwavoliPG4G6BiEwA0cwGnRXfwETL68d51CbA/hxVhrZRdXfWKphPtGQJs//ou1bI="
23
+ gem:
24
+ master: hatenagroup
25
+ on:
26
+ repo: sh19910711/hatenagroup.rb
27
+ ruby: "2.3.0"
28
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hatenagroup.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # HatenaGroup
2
+
3
+ The simple client library for hatena group.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'hatenagroup'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install hatenagroup
20
+
21
+ ## Usage
22
+
23
+ ### Calendar
24
+
25
+ ```ruby
26
+ require "hatenagroup"
27
+
28
+ calendar = HatenaGroup::Calendar.new("mygroup", ENV["HATENA_USER_ID"], ENV["HATENA_PASSWORD"])
29
+ d = calendar.day(Date.new(2016, 4, 1))
30
+ d.body = "Updated Text"
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sh19910711/hatenagroup.rb.
42
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hatenagroup"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hatenagroup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hatenagroup"
8
+ spec.version = Hatenagroup::VERSION
9
+ spec.authors = ["Hiroyuki Sano"]
10
+ spec.email = ["sh19910711@gmail.com"]
11
+
12
+ spec.summary = %q{The simple agent library for hatena group}
13
+ spec.homepage = "https://github.com/sh19910711/hatenagroup.rb"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "mechanize", "~> 2.7.4"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake", "~> 10.5"
24
+ spec.add_development_dependency "rspec", "~> 3.4"
25
+ spec.add_development_dependency "vcr", "~> 3.0"
26
+ spec.add_development_dependency "webmock", "~> 1.24"
27
+ end
@@ -0,0 +1,71 @@
1
+ require 'mechanize'
2
+
3
+ module HatenaGroup
4
+ class Calendar
5
+ def initialize(group, hatena_user_id, hatena_password)
6
+ @group = group
7
+ @agent = Mechanize.new
8
+ agent.log = Logger.new(STDERR)
9
+ agent.log.level = Logger::INFO
10
+ agent.user_agent = USER_AGENT
11
+ login! hatena_user_id, hatena_password
12
+ end
13
+
14
+ def day(d)
15
+ keyword d.strftime("%Y-%m-%d")
16
+ end
17
+
18
+ private
19
+ attr_reader :agent
20
+ attr_reader :group
21
+
22
+ USER_AGENT = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
23
+ HATENA_LOGIN_URL = 'https://www.hatena.ne.jp/login'
24
+
25
+ def login!(hatena_user_id, hatena_password)
26
+ agent.get(HATENA_LOGIN_URL).form_with(:action => '/login') do |form|
27
+ form['name'] = hatena_user_id
28
+ form['password'] = hatena_password
29
+ form['persistent'] = 0
30
+ form.submit
31
+ end
32
+ end
33
+
34
+ def keyword(s)
35
+ Keyword.new agent, group, s
36
+ end
37
+
38
+ class Keyword
39
+ def initialize(agent, group, keyword)
40
+ @agent = agent
41
+ @group = group
42
+ @keyword = keyword
43
+ end
44
+
45
+ def body
46
+ agent.get(read_url).form_with(:name => 'edit', :action => '/keyword').field_with(:name => 'body').value
47
+ end
48
+
49
+ def body=(s)
50
+ agent.get(edit_url).form_with(:name => 'edit', :action => '/keyword') do |form|
51
+ next unless form
52
+ form['body'] = s
53
+ form.submit
54
+ end
55
+ end
56
+
57
+ private
58
+ attr_reader :agent
59
+ attr_reader :keyword
60
+ attr_reader :group
61
+
62
+ def read_url
63
+ "http://#{group}.g.hatena.ne.jp/keyword/#{keyword}?mode=edit&#{Time.now.to_i}"
64
+ end
65
+
66
+ def edit_url
67
+ "http://#{group}.g.hatena.ne.jp/keyword/#{keyword}?mode=edit"
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module Hatenagroup
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "hatenagroup/version"
2
+
3
+ module Hatenagroup
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hatenagroup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroyuki Sano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.24'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.24'
97
+ description:
98
+ email:
99
+ - sh19910711@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - hatenagroup.gemspec
112
+ - lib/hatenagroup.rb
113
+ - lib/hatenagroup/calendar.rb
114
+ - lib/hatenagroup/version.rb
115
+ homepage: https://github.com/sh19910711/hatenagroup.rb
116
+ licenses: []
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.5
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: The simple agent library for hatena group
138
+ test_files: []