Google Books APIsを使ってISBNから書籍情報を取得する
https://www.googleapis.com/books/v1/volumes?q=isbn:[書籍のISBN]
こんな感じになる
$ curl -s https://www.googleapis.com/books/v1/volumes?q=isbn:4582824773 | jq .
{
"items": [
{
"searchInfo": {
"textSnippet": "ひきこもりから瞬く間に「IT長者」へ―驚愕のロングセラー『こんな僕でも社長になれた』を凌ぐ、その後の転落・逃亡・孤立を巡るどん底物語と、都知事選の裏側、そして“い ..."
},
"accessInfo": {
"quoteSharingAllowed": false,
"accessViewStatus": "NONE",
"country": "JP",
"viewability": "NO_PAGES",
"embeddable": false,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": false
},
"pdf": {
"isAvailable": false
},
"webReaderLink": "http://play.google.com/books/reader?id=zV_SsgEACAAJ&hl=&printsec=frontcover&source=gbs_api"
},
"saleInfo": {
"isEbook": false,
"saleability": "NOT_FOR_SALE",
"country": "JP"
},
"volumeInfo": {
"canonicalVolumeLink": "https://books.google.com/books/about/%E6%88%91%E3%81%8C%E9%80%83%E8%B5%B0.html?hl=&id=zV_SsgEACAAJ",
"infoLink": "http://books.google.co.jp/books?id=zV_SsgEACAAJ&dq=isbn:4582824773&hl=&source=gbs_api",
"previewLink": "http://books.google.co.jp/books?id=zV_SsgEACAAJ&dq=isbn:4582824773&hl=&cd=1&source=gbs_api",
"language": "ja",
"imageLinks": {
"thumbnail": "http://books.google.com/books/content?id=zV_SsgEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api",
"smallThumbnail": "http://books.google.com/books/content?id=zV_SsgEACAAJ&printsec=frontcover&img=1&zoom=5&source=gbs_api"
},
"contentVersion": "preview-1.0.0",
"allowAnonLogging": false,
"maturityRating": "NOT_MATURE",
"title": "我が逃走",
"authors": [
"家入一真"
],
"publishedDate": "2015-05-25",
"description": "ひきこもりから瞬く間に「IT長者」へ―驚愕のロングセラー『こんな僕でも社長になれた』を凌ぐ、その後の転落・逃亡・孤立を巡るどん底物語と、都知事選の裏側、そして“いま”を克明に描く衝撃作、満を持して刊行!!",
"industryIdentifiers": [
{
"identifier": "4582824773",
"type": "ISBN_10"
},
{
"identifier": "9784582824773",
"type": "ISBN_13"
}
],
"readingModes": {
"image": false,
"text": false
},
"pageCount": 335,
"printType": "BOOK"
},
"selfLink": "https://www.googleapis.com/books/v1/volumes/zV_SsgEACAAJ",
"etag": "W8tHI2/C/bo",
"id": "zV_SsgEACAAJ",
"kind": "books#volume"
}
],
"totalItems": 1,
"kind": "books#volumes"
}
登録とかなしでここまでの情報が取れるのは便利
本の定価が取れたらよかったんだけどなあ
Rubyのクラスの書き方
簡単なのにいつも忘れるからメモ。マジでメモ。
class User
attr_accessor :name, :age
def initialize(name, age)
@name = name
@age = age
end
end
DBをMySQLでRailsアプリケーションを作成する
rails new mysql_app -d mysql
これでDBはMySQLになる。デフォルトはSQLite。
Gemfileにも
gem 'mysql2', '>= 0.3.18', '< 0.6.0'
config/database.ymlにも
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
socket: /var/lib/mysql/mysql.sock
mysql2となっているので、MySQLが使えるようになったことがわかる。
Rubyでメールを送信する方法(Gmail)
gemのインストール
$ sudo gem install mail
Rubyソースコード
require 'mail'
mail = Mail.new
options = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'smtp.gmail.com',
:user_name => 'アカウント@gmail.com',
:password => 'パスワード',
:authentication => :plain,
:enable_starttls_auto => true
}
mail.charset = 'utf-8'
mail.from '送信元アドレス@gmail.com'
mail.to '送信先アドレス@gmail.com'
mail.subject '件名'
mail.body '内容'
mail.delivery_method(:smtp, options)
mail.deliver
TwitterのGemを入れようとしたら、エラー吐いた&その対処法
TwitterのGemを入れようとしたら
$ sudo gem install twitter
Building native extensions. This could take a while...
ERROR: Error installing twitter:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/http_parser.rb-0.6.0 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser/gem_make.out
なんかエラー吐いた
どうやらCommand Line Developer Toolsが必要らしい
$ xcode-select --install
それに加えて、Xcodeのライセンスに同意しないといけないので
$ sudo xcodebuild -license
これでやっとうまくいく