質問編集履歴

2

質問削除の取り消し

2018/02/21 01:50

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,231 @@
1
+ #### 以下課題に取り組んでいます。
2
+
3
+
4
+
5
+ > 以下の3つのWeb APIがあります(実際にアクセスできます)。これらを利用して、あるユーザーIDをあたえたときのユーザー名および登録金融機関一覧と、登録金融機関の残高(balance)を出力するプログラムを作成してください。 なお、プログラムはオブジェクト指向プログラミングに基づく設計・実装をしてください。
6
+
7
+
8
+
9
+ ```json:hoge.json
10
+
11
+
12
+
13
+ - Web API
14
+
15
+ - https://salty-forest-61016.herokuapp.com/users/1
16
+
17
+ - レスポンス例
18
+
19
+ {
20
+
21
+ attributes: {
22
+
23
+ id: 1,
24
+
25
+ name: "Alice",
26
+
27
+ account_ids: [
28
+
29
+ 1,
30
+
31
+ 3,
32
+
33
+ 5
34
+
35
+ ]
36
+
37
+ }
38
+
39
+ }
40
+
41
+ - https://salty-forest-61016.herokuapp.com/users/1/accounts
42
+
43
+ - レスポンス例
44
+
45
+ [
46
+
47
+ {
48
+
49
+ attributes: {
50
+
51
+ id: 1,
52
+
53
+ user_id: 1,
54
+
55
+ name: "A銀行",
56
+
57
+ balance: 20000
58
+
59
+ }
60
+
61
+ },
62
+
63
+ {
64
+
65
+ attributes: {
66
+
67
+ id: 3,
68
+
69
+ user_id: 1,
70
+
71
+ name: "C信用金庫",
72
+
73
+ balance: 120000
74
+
75
+ }
76
+
77
+ },
78
+
79
+ {
80
+
81
+ attributes: {
82
+
83
+ id: 5,
84
+
85
+ user_id: 1,
86
+
87
+ name: "E銀行",
88
+
89
+ balance: 5000
90
+
91
+ }
92
+
93
+ }
94
+
95
+ ]  
96
+
97
+
98
+
99
+ - https://salty-forest-61016.herokuapp.com/accounts/2
100
+
101
+ - レスポンス例
102
+
103
+ {
104
+
105
+ attributes: {
106
+
107
+ id: 2,
108
+
109
+ user_id: 2,
110
+
111
+ name: "Bカード",
112
+
113
+ balance: 200
114
+
115
+ }
116
+
117
+ }
118
+
119
+
120
+
121
+ ```
122
+
123
+
124
+
125
+ # Qiitaで独学しました。
126
+
127
+
128
+
129
+ 課題を解く前に、独学で自分なりにQiitaにまとめました。
130
+
131
+ [Web API 学習(非公開記事)](https://qiita.com/rik0/private/faac37174ac7af507718)
132
+
133
+
134
+
135
+
136
+
137
+ #### 個人的回答(最低限回答になってます。)
138
+
139
+
140
+
141
+ ※ 最低限の回答 ... `$ ruby hoge.rb`で動く。
142
+
143
+
144
+
145
+ ```
146
+
147
+ require 'net/http'
148
+
149
+ require 'uri'
150
+
151
+ require 'json'
152
+
153
+
154
+
155
+ class User
156
+
157
+ attr_reader :userid
158
+
159
+
160
+
161
+ def initialize(userid)
162
+
163
+ @userid = userid
164
+
165
+ end
166
+
167
+
168
+
169
+ def name
170
+
171
+ url = URI.parse("https://salty-forest-61016.herokuapp.com/users/#{@userid}")
172
+
173
+ json = Net::HTTP.get(url)
174
+
175
+ user = JSON.parse(json)
176
+
177
+ puts user['attributes']['name']
178
+
179
+ end
180
+
181
+
182
+
183
+ def accounts
184
+
185
+ url = URI.parse("https://salty-forest-61016.herokuapp.com/users/#{@userid}/accounts")
186
+
187
+ json = Net::HTTP.get(url)
188
+
189
+ accounts = JSON.parse(json)
190
+
191
+ accounts.each do |account|
192
+
193
+ puts "銀行名:#{account["attributes"]["name"]}(残高: #{account['attributes']['balance']}円)"
194
+
195
+ end
196
+
197
+ end
198
+
199
+ end
200
+
201
+
202
+
203
+ user = User.new(1)
204
+
205
+
206
+
207
+ user.name
208
+
209
+ # Alice
210
+
211
+
212
+
213
+ user.accounts
214
+
215
+ # 銀行名:A銀行(残高: 20000円)
216
+
217
+ # 銀行名:C信用金庫(残高: 120000円)
218
+
219
+ # 銀行名:E銀行(残高: 5000円)
220
+
221
+
222
+
223
+
224
+
225
+ ```
226
+
227
+ `$ ruby hoge.rb`で動かしています。
228
+
1
229
  #### もっと良いコードにしてみたい
2
230
 
3
231
 

1

なし。

2018/02/21 01:50

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,235 +1,3 @@
1
- #### 以下課題に取り組んでいます。
2
-
3
-
4
-
5
- > 以下の3つのWeb APIがあります(実際にアクセスできます)。これらを利用して、あるユーザーIDをあたえたときのユーザー名および登録金融機関一覧と、登録金融機関の残高(balance)を出力するプログラムを作成してください。 なお、プログラムはオブジェクト指向プログラミングに基づく設計・実装をしてください。
6
-
7
-
8
-
9
- ```json:hoge.json
10
-
11
-
12
-
13
- - Web API
14
-
15
- - https://salty-forest-61016.herokuapp.com/users/1
16
-
17
- - レスポンス例
18
-
19
- {
20
-
21
- attributes: {
22
-
23
- id: 1,
24
-
25
- name: "Alice",
26
-
27
- account_ids: [
28
-
29
- 1,
30
-
31
- 3,
32
-
33
- 5
34
-
35
- ]
36
-
37
- }
38
-
39
- }
40
-
41
- - https://salty-forest-61016.herokuapp.com/users/1/accounts
42
-
43
- - レスポンス例
44
-
45
- [
46
-
47
- {
48
-
49
- attributes: {
50
-
51
- id: 1,
52
-
53
- user_id: 1,
54
-
55
- name: "A銀行",
56
-
57
- balance: 20000
58
-
59
- }
60
-
61
- },
62
-
63
- {
64
-
65
- attributes: {
66
-
67
- id: 3,
68
-
69
- user_id: 1,
70
-
71
- name: "C信用金庫",
72
-
73
- balance: 120000
74
-
75
- }
76
-
77
- },
78
-
79
- {
80
-
81
- attributes: {
82
-
83
- id: 5,
84
-
85
- user_id: 1,
86
-
87
- name: "E銀行",
88
-
89
- balance: 5000
90
-
91
- }
92
-
93
- }
94
-
95
- ]  
96
-
97
-
98
-
99
- - https://salty-forest-61016.herokuapp.com/accounts/2
100
-
101
- - レスポンス例
102
-
103
- {
104
-
105
- attributes: {
106
-
107
- id: 2,
108
-
109
- user_id: 2,
110
-
111
- name: "Bカード",
112
-
113
- balance: 200
114
-
115
- }
116
-
117
- }
118
-
119
-
120
-
121
- ```
122
-
123
-
124
-
125
- # Qiitaで独学しました。
126
-
127
-
128
-
129
- 課題を解く前に、独学で自分なりにQiitaにまとめました。
130
-
131
- [Web API 学習(非公開記事)](https://qiita.com/rik0/private/faac37174ac7af507718)
132
-
133
-
134
-
135
-
136
-
137
- #### 個人的回答(最低限回答になってます。)
138
-
139
-
140
-
141
- ※ 最低限の回答 ... `$ ruby hoge.rb`で動く。
142
-
143
-
144
-
145
- ```
146
-
147
- require 'net/http'
148
-
149
- require 'uri'
150
-
151
- require 'json'
152
-
153
-
154
-
155
- class User
156
-
157
- attr_reader :userid
158
-
159
-
160
-
161
- def initialize(userid)
162
-
163
- @userid = userid
164
-
165
- end
166
-
167
-
168
-
169
- def name
170
-
171
- url = URI.parse("https://salty-forest-61016.herokuapp.com/users/#{@userid}")
172
-
173
- json = Net::HTTP.get(url)
174
-
175
- user = JSON.parse(json)
176
-
177
- puts user['attributes']['name']
178
-
179
- end
180
-
181
-
182
-
183
- def accounts
184
-
185
- url = URI.parse("https://salty-forest-61016.herokuapp.com/users/#{@userid}/accounts")
186
-
187
- json = Net::HTTP.get(url)
188
-
189
- accounts = JSON.parse(json)
190
-
191
- accounts.each do |account|
192
-
193
- puts "銀行名:#{account["attributes"]["name"]}(残高: #{account['attributes']['balance']}円)"
194
-
195
- end
196
-
197
- end
198
-
199
- end
200
-
201
-
202
-
203
- user = User.new(1)
204
-
205
-
206
-
207
- user.name
208
-
209
- # Alice
210
-
211
-
212
-
213
- user.accounts
214
-
215
- # 銀行名:A銀行(残高: 20000円)
216
-
217
- # 銀行名:C信用金庫(残高: 120000円)
218
-
219
- # 銀行名:E銀行(残高: 5000円)
220
-
221
-
222
-
223
-
224
-
225
- ```
226
-
227
- `$ ruby hoge.rb`で動かしています。
228
-
229
-
230
-
231
-
232
-
233
1
  #### もっと良いコードにしてみたい
234
2
 
235
3